首頁 >後端開發 >php教程 >解决php json_encode 出现的中文转码、乱码问题_PHP教程

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

WBOY
WBOY原創
2016-07-13 10:34:12815瀏覽

<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