<?php
function GetPreferredLanguages() {
if ( empty( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] ) ) {
return null;
}
$hi_code = '';
$hi_pri = 0;
$langs = explode( ",", $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] );
$prefs = array ();
foreach ( $langs as $lang ) {
list( $codelang, $priority ) = explode( ";", $lang );
if ( empty( $priority ) ) {
$priority = 1;
$prefs[ $codelang ] = 1;
}
else {
$prefs[ $codelang ] = substr( $priority, 2 );
}
if ( $priority > $hi_pri ) {
$code = substr( $codelang, 0, 2 );
$hi_code = $code;
$hi_pri = $priority;
}
}
return array (
"lang" => $hi_code, "priority" => $hi_pri, "prefs" => $prefs,
"raw" => $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ],
);
}
$list = GetLanguagePrefs( );
/*
Array
(
[lang] => en
[priority] => 1
[prefs] => Array
(
[en-US] => 1
[en] => 0.8
[zh-TW] => 0.6
[zh] => 0.4
[es] => 0.2
[it] => 0.2
[fr] => 0.2
)
[raw] => en-US,en;q=0.8,zh-TW;q=0.6,zh;q=0.4,es;q=0.2,it;q=0.2,fr;q=0.2
)
*/
Get a list of the preferred languages and the top priority pick.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.