Home > php教程 > php手册 > body text

php+jquery+json中文乱码

WBOY
Release: 2016-05-25 16:52:54
Original
1814 people have browsed it

今天我们利用了正则表达式来判断preg_replace替换由jquery转义过来的如\u5c71\u4e1c,但有的时间还是会出现中文问题.

利用iconv函数解决代码如下:

<?php  
	$code = json_encode($str);  
	$code = preg_replace("#u([0-9a-f]+)#ie", "iconv(&#39;UCS-2&#39;, &#39;UTF-8&#39;, pack(&#39;H4&#39;, &#39;1&#39;))", $code);  
?>
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template