Skip to content

Instantly share code, notes, and snippets.

View thg2k's full-sized avatar
🏠
Working from home

Giovanni Giacobbi thg2k

🏠
Working from home
  • Padova, Italy
View GitHub Profile
@thg2k
thg2k / accept_lang.php
Created February 21, 2020 13:32
Parse HTTP header Accept-Language
<?php
function get_http_accept_language($accept_language = null) {
if (($accept_language == "") && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$langs = array();
if (preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)\s*(?:;\s*q\s*=\s*(1|0\.[0-9]+))?/i',