Home > Backend Development > PHP Tutorial > 手机交付搜索中文全部变成了“???????¤????”“???·?±??????”“?????????·??”

手机交付搜索中文全部变成了“???????¤????”“???·?±??????”“?????????·??”

WBOY
Release: 2016-06-13 11:05:51
Original
990 people have browsed it

手机提交搜索中文全部变成了“???????¤????”“???·?±??????”“?????????·??”

本帖最后由 default7 于 2012-12-23 13:10:17 编辑 很奇怪的现象:
(1)使用手机进行关键词搜索,中文全部变成了“?????????·??”、拉丁字符的那种种。
(2)使用is_utf8检测$_GET[kw]返回的是utf-8的编码的。
(3)手机访问文件最开头直接 echo $_GET[kw]也是这个样子。。。电脑访问不是

相关配置:
(1)数据库类型MyISAM,表字符集utf8_general_ci,字段kw字符集 utf8_general_ci<br />(2)PHP版本:PHP Version 5.2.17,CGI/fast CGI<br />(3)System 	Linux sasin 2.6.32.36-hardened #9 SMP Tue Mar 29 09:29:20 PDT 2011 x86_64 <br />(4)手机相关信息:<br />HTTP_ACCEPT_ENCODING = gzip <br />HTTP_ACCEPT_LANGUAGE = zh-CN <br />HTTP_USER_AGENT = Mozilla/5.0 (Linux; U; Android 2.3; zh-cn;HTC Build/GRJ90) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 <br />HTTP_ACCEPT = application/xml,application/vnd.wap.xhtml+xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,text/vnd.wap.wml;q=0.6,*/*;q=0.5,UC/145,plugin/1 <br />REMOTE_PORT = 49279 <br />REQUEST_METHOD = GET<br />(5)手机浏览器 UC:8.7.2.214 Android<br /><br />
Copy after login


例子搜索的几个关键词:
引用
广州 -> ?????????·??
深圳 -> ???·?±??????
北京 -> ???????¤????



PHP函数 is_utf8(),来自PHP官网
<br />function is_utf8($str) {<br />    $c=0; $b=0;<br />    $bits=0;<br />    $len=strlen($str);<br />    for($i=0; $i<$len; $i++){<br />        $c=ord($str[$i]);<br />        if($c > 128){<br />            if(($c >= 254)) return false;<br />            elseif($c >= 252) $bits=6;<br />            elseif($c >= 248) $bits=5;<br />            elseif($c >= 240) $bits=4;<br />            elseif($c >= 224) $bits=3;<br />            elseif($c >= 192) $bits=2;<br />            else return false;<br />            if(($i+$bits) > $len) return false;<br />            while($bits > 1){<br />                $i++;<br />                $b=ord($str[$i]);<br />                if($b < 128 || $b > 191) return false;<br />                $bits--;<br />            }<br />        }<br />    }<br />    return true;<br />}<br />
Copy after login






------解决方案--------------------
先发一个语言声明的头,看看
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