Home  >  Article  >  Backend Development  >  二维码解析后文字乱码

二维码解析后文字乱码

WBOY
WBOYOriginal
2016-06-23 13:46:161366browse


如图二维码
扫描后解析出来是乱码
urlencode后是如下内容
%C2%B0%C3%99%C2%B6%C3%88%C2%B0%C3%99%C2%BF%C3%86%C2%A3%C2%AD%C2%B6%C3%BE%C3%8E%C2%AC%C3%82%C3%AB%C2%B4%C3%8A%C3%8C%C3%B5
我用微信扫描解析却是可以的
内容是"百度百科-二维码词条"
这是经过了什么编码处理过么?怎么才能得到真正的结果?


回复讨论(解决方案)

http://cli.im/deqr
使用这个解析器也是

$s = '%C2%B0%C3%99%C2%B6%C3%88%C2%B0%C3%99%C2%BF%C3%86%C2%A3%C2%AD%C2%B6%C3%BE%C3%8E%C2%AC%C3%82%C3%AB%C2%B4%C3%8A%C3%8C%C3%B5';$s = urldecode($s);echo utf8_decode($s);
百度百科-二维码词条

解得的串是 gbk 编码的

大神现身立马解决问题了,
现在还有一个疑问,请问我应该如何判断什么时候应该用utf8_decode呢

这样判断能看明白吗

$s = '%C2%B0%C3%99%C2%B6%C3%88%C2%B0%C3%99%C2%BF%C3%86%C2%A3%C2%AD%C2%B6%C3%BE%C3%8E%C2%AC%C3%82%C3%AB%C2%B4%C3%8A%C3%8C%C3%B5';$s = urldecode($s);if(mb_check_encoding('utf-8')) {  $n = 0;  for($i=0; $i<strlen($s); $i+=2) if((ord($s{$i}) & 0xf0) == 192) $n++;  if($n > strlen($s)/2 * 0.8) $s = utf8_decode($s);}echo $s;

其实直接统计原串中 %C 的个数也是一样的

我刚才自己尝试的用mb_detect_encoding(utf8_decode('阿萨德asda'))=='ASCII' 这样来判断需要用
不知道这样精确不

Statement:
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