Maison > Article > développement back-end > 解决php json_encode 出现的中文转码、乱码问题_PHP教程
<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>);