Heim > Backend-Entwicklung > PHP-Tutorial > 过路的牛牛们,帮小菜看下这段代码吧解决思路

过路的牛牛们,帮小菜看下这段代码吧解决思路

WBOY
Freigeben: 2016-06-13 12:16:29
Original
1038 Leute haben es durchsucht

过路的牛牛们,帮小菜看下这段代码吧
想通过取得UA中的语言编码信息实现跳转,功能:如果UA包含非zh-CN的编码,跳转之,未设置语言信息的不跳转,
不是程序,自己查函数下午搞到现在还没实验成功,条件加循环就晕了,输出一堆no搞不定,大牛小牛帮帮忙,多谢啦!

<br />$ua = $_SERVER['HTTP_USER_AGENT']; <br />$lang = array("af-ZA","sq-AL","ar-DZ","ar-BH","ar-EG","ar-IQ","ar-JO","ar-KW","ar-LB","ar-LY","ar-MA","ar-OM","ar-QA","ar-SA","ar-SY","ar-TN","ar-AE","ar-YE","hy-AM","az Azeriaz-AZ-Cyrl","az-AZ-Latn Azeri","eu-ES","be-BY","bg-BG","ca-ES","zh-HK","zh-MO","zh-CN","zh-CHS","zh-SG","zh-TW","zh-CHT","hr-HR","cs-CZ","da-DK","div-MV","nl-BE","nl-NL","en-AU","en-BZ","en-CA","en-CB","en-IE","en-JM","en-NZ","en-PH","en-ZA","en-TT","en-GB","en-US","en-ZW","et-EE","fo-FO","fa-IR","fi-FI","fr-BE","fr-CA","fr-FR","fr-LU","fr-MC","fr-CH","gl-ES","ka-GE","de-AT","de-DE","de-LI","de-LU","de-CH","el-GR","gu-IN","he-IL","hi-IN","hu-HU","is-IS","id-ID","it-IT","it-CH","ja-JP","kn-IN","kk-KZ","kok-IN","ko-KR","ky-KZ","lv-LV","lt-LT","mk-MK","ms-BN","ms-MY","mr-IN","mn-MN","nb-NO","nn-NO","pl-PL","pt-BR","pt-PT","pa-IN","ro-RO","ru-RU","sa-IN","sr-SP-Cyrl","sr-SP-Latn","sk-SK","sl-SI","es-AR","es-BO","es-CL","es-CO","es-CR","es-DO","es-EC","es-SV","es-GT","es-HN","es-MX","es-NI","es-PA","es-PY","es-PE","es-PR","es-ES","es-UY","es-VE","sw-KE","sv-FI","sv-SE","syr-SY","ta-IN","tt-RU","te-IN","th-TH","tr-TR","uk-UA","ur-PK","uz-UZ-Cyrl","uz-UZ-Latn","vi-VN");<br /><br />for($i=0;$i<136;$i++){<br />if(is_numeric(stripos($ua,$lang[$i])) == false){<br />	echo "no";<br />}else{<br />	echo "yes";<br />}<br />}<br /><br />
Nach dem Login kopieren

------解决思路----------------------
需求是中文不跳转,非中文跳转吗?

获取客户端浏览器使用的语言应该是从$_SERVER["HTTP_ACCEPT_LANGUAGE"]中截取的。

举个栗子
<br />if (preg_match("/zh/i", substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4)))  {<br />    echo "不跳转";<br />}else {<br />    echo "跳转";<br />}<br />
Nach dem Login kopieren



------解决思路----------------------
首先HTTP_ACCEPT_LANGUAGE已经提到了
其次,需求是非zh的编码跳转,你大可不必将所有的可能都列出来,用stripos判定一次即可
最后遍历数组可以试试foreach

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage