首页  >  文章  >  后端开发  >  解决php json_encode 出现的中文转码、乱码问题_PHP教程

解决php json_encode 出现的中文转码、乱码问题_PHP教程

WBOY
WBOY原创
2016-07-13 10:34:12791浏览

<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>);

 

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( );...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn