×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Bob Ray
Added: Jul 16, 2015 10:20 PM
Modified: Jul 16, 2015 10:35 PM
Views: 13
Gets language key from user's browser
  1. /* Original code by Mohit Madan @TheMohitMadan */
  2. function get_client_language($availableLanguages, $default='en'){
  3.         if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  4.                 $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  5.  
  6.                 foreach ($langs as $value){
  7.                         $choice=substr($value,0,2);
  8.                         if(in_array($choice, $availableLanguages)){
  9.                                 return $choice;
  10.                         }
  11.                 }
  12.         }
  13.         return $default;
  14. }