PHP如何识别系统语言或浏览器语言

preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$lang = $matches[1];
switch ($lang) {
    case 'zh-cn' :
        //header('Location: http://cn.test.com/');
        echo "中国";
        break;
    case 'zh-tw' :
        // header('Location: http://tw.test.com/');
        echo "台湾";
        break;
    case 'ko' :
        //header('Location: http://ko.test.com/');
        break;
    default:
        // header('Location: http://en.test.com/');
        echo "英文";
        break;
}
posted @ 2024-05-06 18:24  mingruqi  阅读(30)  评论(0编辑  收藏  举报