Return to Snippet

Revision: 12014
at March 29, 2010 08:35 by ping_ch


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

Revision: 12013
at March 29, 2010 08:35 by ping_ch


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

Revision: 12012
at February 27, 2009 04:50 by ping_ch


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

Initial URL
php-detect-browser-language

Initial Description
Just provide $availableLanguages as an array('en', 'de', 'es')

Initial Title
Detect Browser Language

Initial Tags
http, browser

Initial Language
PHP