Home > Backend Development > PHP Tutorial > PHP怎么识别系统语言或浏览器语言

PHP怎么识别系统语言或浏览器语言

WBOY
Release: 2016-06-13 11:23:09
Original
1218 people have browsed it

PHP如何识别系统语言或浏览器语言
有两个站cn,en
需要当在国外访问cn的时候直接跳转到en去
请问有什么方法可以完成。
我用的

<br />preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);<br />$lang = $matches[1];<br />switch ($lang) {<br />	case 'zh-cn' :<br />		//header('Location: http://cn.test.com/');<br />		echo "中国";<br />		break;<br />	case 'zh-tw' :<br />		// header('Location: http://tw.test.com/');<br />		echo "台湾";<br />		break;<br />	case 'ko' :<br />		//header('Location: http://ko.test.com/');<br />		break;<br />	default:<br />		// header('Location: http://en.test.com/');<br />		echo "英文";<br />		break;<br />}<br />
Copy after login

火狐和IE显示的不同,IE是正常的。
如直接显示$_SERVER['HTTP_ACCEPT_LANGUAGE']
IE为:zh-cn
火狐为:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template