Home >php教程 >php手册 >解决php json_encode 出现的中文转码、乱码问题

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

WBOY
WBOYOriginal
2016-06-13 09:39:21913browse

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

 

Statement:
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