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

1 // 防止json中文转码

2 function jsonEncodeWithCN($data) {

3     return preg_replace("/\\\u([0-9a-f]{4})/ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '$1'))", json_encode($data));

4 }

5 

6 $arr = array('a'=>'测试', b=>'hello');

7 

8 echo jsonEncodeWithCN($arr);

 

你可能感兴趣的:(encode)