Using the below PHP snippet you would be able to detect the language of your user’s browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
}
return $default;
|
0 comments:
Post a Comment