/ Published in: PHP
Function to detect user language in php.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getPreferredLanguage() { // break up string into pieces (languages and q factors) $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); // create a list like "en" => 0.8 // set default to 1 for any without q factor foreach ($langs as $lang => $val) { if ($val === '') $langs[$lang] = 1; } // sort list based on value } } //extract most important (first) foreach ($langs as $lang => $val) { break; } //if complex language simplify it return $lang; }
URL: http://www.barattalo.it/2009/12/16/detect-user-language-with-php/