Home > Backend Development > PHP Tutorial > Solve the Chinese transcoding and garbled problems in php json_encode_PHP Tutorial

Solve the Chinese transcoding and garbled problems in php json_encode_PHP Tutorial

WBOY
Release: 2016-07-13 10:34:12
Original
805 people have browsed it

<span 1</span> <span //</span><span  防止json中文转码</span>
<span 2</span> <span function</span> jsonEncodeWithCN(<span $data</span><span ) {
</span><span 3</span>     <span return</span> <span preg_replace</span>("/\\\u([0-9a-f]{4})/ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '$1'))", json_encode(<span $data</span><span ));
</span><span 4</span> <span }
</span><span 5</span> 
<span 6</span> <span $arr</span> = <span array</span>('a'=>'测试', b=>'hello'<span );
</span><span 7</span> 
<span 8</span> <span echo</span> jsonEncodeWithCN(<span $arr</span>);
Copy after login

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/752222.htmlTechArticlejsonEncodeWithCN( ("/\\\u([0-9a-f]{4})/ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '$1'))", json_encode( = ('a'='测试', b='hello' jsonEncodeWithCN( );...
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