verbose/lib/getfirstbrowserlang.php
2023-11-20 12:42:57 +01:00

20 lines
499 B
PHP

<?php
function getfirstbrowserlang($default='en') {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=[];
$buff=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($buff as $ent) {
$ent=trim($ent);
$ent=explode(';',$ent);
(count($ent)<2) ? $ent[1]=1 : $ent[1]=preg_replace('/^q=/','',$ent[1])+0;
$ent[0]=locale_canonicalize($ent[0]);
$langs[$ent[0]]=$ent[1];
}
arsort($langs);
$blang=array_key_first($langs);
return $blang;
} else {
return $default;
}
}
?>