determine language of visitor

Develop software to help the small bookshop owner to catalog & sell online.

New Project started 2021
User avatar
Stevyn
SysOp
Posts:1786
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:
determine language of visitor

Post by Stevyn » Mon May 03, 2021 11:46 am

determine language of visitor

checking for english & japanese

Code: Select all

 $value="en";
   if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
  if (count($lang_parse[1])){
    $langs = array_combine($lang_parse[1], $lang_parse[4]);
    foreach ($langs as $lang => $val){
      if ($val === '') $langs[$lang] = 1;
    }
    arsort($langs, SORT_NUMERIC);
  }
  foreach ($langs as $lang => $val){
    if (strpos($lang,'en')===0){
      $value = 'en';
      break;
    } else if (strpos($lang,'ja')===0){
      $value = 'ja';
    }
  }
} 
  
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

Post Reply