Two ways to solve the garbage problem in PHP function to handle Chinese json_encode

$code = json_encode($str);
 return preg_replace("#\\\u(([0-9a-f]+?){4})#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $code);

Or use


$new_arr = array();
foreach($arr as $key=>$val){
 $new_arr[$key] = urlencode($val);
}
print_r($new_arr);
echo $json_arr = urldecode(json_encode($new_arr));


Has been updated, you can use

json_decode($json,JSON_UNESCAPED_UNICODE);




Published 27 original articles · won praise 53 · views 160 000 +

Guess you like

Origin blog.csdn.net/auspi12341/article/details/17397749