Skip to content

Instantly share code, notes, and snippets.

@leadscloud
Last active December 18, 2015 14:08
Show Gist options
  • Save leadscloud/5794579 to your computer and use it in GitHub Desktop.
Save leadscloud/5794579 to your computer and use it in GitHub Desktop.
检测浏览器语言
/*检测浏览器语言*/
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
//start going through each one
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
}
return $default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment