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

 

posted @ 2014-04-10 13:00  辰阳  阅读(621)  评论(2编辑  收藏  举报