用户可接受的语言信息,放在$_SERVER['HTTP_ACCEPT_LANGUAGE']里,变量信息是类似这样的 "zh-cn", 假如是多语言列,是类似 "zh-cn,en;q=0.8,ko;q=0.5,zh-tw;q=0.3",下面的问题可以迎刃而解了,代码:
- <?php
- error_reporting(E_ALL ^ E_NOTICE);
-
-
- preg_match('/^([a-z-] )/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
- $lang = $matches[1];
- switch ($lang) {
- case 'zh-cn' :
- header('Location: http://cn.example.com/');
- break;
- case 'zh-tw' :
- header('Location: http://tw.example.com/');
- break;
- case 'ko' :
- header('Location: http://ko.example.com/');
- break;
- default:
- header('Location: http://en.example.com/');
- break;
- }
- ?>
|