欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

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


$ua = $_SERVER['HTTP_USER_AGENT'];
$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");

for($i=0;$iif(is_numeric(stripos($ua,$lang[$i])) == false){
echo "no";
}else{
echo "yes";
}
}


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

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

举个栗子

if (preg_match("/zh/i", substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4))) {
echo "不跳转";
}else {
echo "跳转";
}



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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频