noganno
9/14/2013 - 8:23 AM

Just provide $availableLanguages as an array('en', 'de', 'es') http://snipplr.com/view/12631/detect-browser-language/php-detect-browser-lang

Just provide $availableLanguages as an array('en', 'de', 'es') http://snipplr.com/view/12631/detect-browser-language/php-detect-browser-language

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;
}