Posted By

ping_ch on 02/27/09


Tagged

http browser detection language locale acceptlanguage


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

umang_nine
ping_ch
vali29
jnbn
aleksanderek
BrianCoyDesign
galofre
ninjacharlee
dext
o0110o
tux-world


Detect Browser Language


 / Published in: PHP
 

URL: php-detect-browser-language

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

  1. function get_client_language($availableLanguages, $default='en'){
  2.  
  3. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  4.  
  5. $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  6.  
  7. //start going through each one
  8. foreach ($langs as $value){
  9.  
  10. $choice=substr($value,0,2);
  11. if(in_array($choice, $availableLanguages)){
  12. return $choice;
  13.  
  14. }
  15.  
  16. }
  17. }
  18. return $default;
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: maiis on February 25, 2010

You have to write: HTTPACCEPTLANGUAGE all in capitals letters. Regards, Maïs

You need to login to post a comment.