Home  >  Article  >  Backend Development  >  PHP can detect code snippets in the language used by the user's browser

PHP can detect code snippets in the language used by the user's browser

WBOY
WBOYOriginal
2016-07-25 08:42:44968browse

Use the following PHP code snippet to detect the language used by the user's browser

  1. function get_client_language($availableLanguages, $default='en'){
  2. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  3. $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  4. foreach ($langs as $value){
  5. $choice=substr($value,0,2);
  6. if(in_array($choice , $availableLanguages)){
  7. return $choice;
  8. }
  9. }
  10. }
  11. return $default;
  12. }
Copy code

PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn