Skip to content

Instantly share code, notes, and snippets.

@gr8pathik
Created December 2, 2013 13:03
Show Gist options
  • Save gr8pathik/7749122 to your computer and use it in GitHub Desktop.
Save gr8pathik/7749122 to your computer and use it in GitHub Desktop.
Detect browser language - PHP Language - Source: http://snipplr.com/view/12631/detect-browser-language/
<?php
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment