Home > Backend Development > PHP Tutorial > Automatically identify the browser language and switch between Chinese and English (php and Js versions)

Automatically identify the browser language and switch between Chinese and English (php and Js versions)

WBOY
Release: 2016-07-25 08:59:18
Original
1383 people have browsed it
  1. error_reporting(E_ALL ^ ​​E_NOTICE);
  2. // Analyze the attributes of HTTP_ACCEPT_LANGUAGE
  3. // Only the first language setting is taken here (other functions can be enhanced as needed)
  4. //Search and organize bbs.it -home.org
  5. preg_match('/^([a-z-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
  6. $lang = $matches[1];
  7. switch ($lang) {
  8. case 'zh-cn' :
  9. header('Location: http://cn.jbxue.com/');
  10. break;
  11. case 'zh-tw' :
  12. header('Location: http://tw. jbxue.com/');
  13. break;
  14. case 'ko' :
  15. header('Location: http://ko.jbxue.com/');
  16. break;
  17. default:
  18. header('Location: http:/ /en.jbxue.com/');
  19. break;
  20. }
  21. ?>
Copy code

2, JS-based method:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template