function get_pref_language_array($str_http_languages)
{
$langs = explode(',',$str_http_languages);
$qcandidat = 0;
$nblang = count($langs);
for ($i=0; $i<$nblang; $i++)
{
for ($j=0; $j<count($langs); $j++) {
$lang = trim($langs[$j]); // Supprime les espaces avant et après $lang
// Lang est de la forme langue;q=valeur
if (!strstr($lang, ';') && $qcandidat != 1) {
// Si la chaine ne contient pas de valeur de préférence q
$candidat = $lang;
$qcandidat = 1;
$indicecandidat = $j;
}
else {
// On récupère l'indice q
$q = ereg_replace('.*;q=(.*)', '\\1', $lang);
if ($q > $qcandidat) {
$candidat = ereg_replace('(.*);.*', '\\1', $lang); ;
$qcandidat = $q;
$indicecandidat = $j;
}
}
}
$resultat[$i] = $candidat;
$qcandidat=0;
// On supprime la valeur du tableau
unset($langs[$indicecandidat]);
$langs = array_values($langs);
}
return $resultat;
}
I wrote that function once to detect the language, it's a bit more rfc compliant in that if I anderstand the above code correctly, you assume the first language given is the prefered one, wich is in most case true, but it's not defined that precisely in the RFC.
This function takes $_SERVER['HTTP_ACCEPT_LANGUAGE'] as parameter, and returns an array containg the languages, beginning with the prefered one, and sorted by preference.
Hope this helps.