Example, php json_encode Chinese transcoding and garbled code problems.
-
-
// Prevent json Chinese transcoding - function jsonEncodeWithCN($data) {
- return preg_replace("/\u([0-9a-f]{4} )/ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '$1'))", json_encode($data));
- }
- < p>$arr = array('a'=>'test', b=>'hello');
echo jsonEncodeWithCN($arr);
-
Copy code
|