php把u5c0fu533au7eff乱码转换成中文
Jun 02, 2016 am 09:14 AM
iconv
今天公司在做一个数据与app对接的功能,对方转过来的是json转义之后的数据,但又不是标准的json格式化数据,我们直接使用json_decode是输入原字符了,下面一起来看年解决办法吧。
代码如下
\u5c0f\u533a\u7eff\u5316\u5f88\u4e0d\u9519|||\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684|||\u4e8c\u671f\u4ea4\u623f\u4e86|||\u548c\u683c\u6797\u4e91\u5885\u79bb\u5f97\u5f88\u8fd1|||\u5730\u7406\u4f4d\u7f6e
Copy after login
上面代码有人能看懂吗?我估计没人了,我知道是json了所以取一段出来测试
echo json_decode('u683c\u8fd8\u4e0d\u9519');
Copy after login
发现什么出没有输入,后来想这个不是标准json我们可以使用一个数组再转换看一下
$array =array('u683c\u8fd8\u4e0d\u9519'); echo json_encode( $array ) ;
Copy after login
得到结果是
["u683c\\u8fd8\\u4e0d\\u9519"]
Copy after login
这不是标准json格式数据吧,于时我再进一步解析
$array = json_decode('["\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684"]');
Copy after login
print_r($array ); ( [0] => 浜???浠€涔??跺??浜ゆ?跨?? ) 是
Copy after login
乱码呀,这个我估计是编码问题,我知道json转换编码是uft8的而我页面是gbk了,于时找到iconv函数
$array = json_decode('["\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684"]'); echo iconv('utf-8','gbk',$array[0]);
Copy after login
得出结果是
二期什么时候交房的
这样就成功把乱码转换成中文了哦,大家试一下
本站原创教程:转载注明来源http://www.phprm.com
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
