欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php json_encode unicode decode

程序员文章站 2022-04-15 18:45:46
...
 '你好',        'b' => 'bb');//header('Content-Type:application/json; charset=UTF-8');echo json_encode($a)."\n";function decodeUnicode($str){    return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',        create_function(            '$matches',            'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'        ),        $str);}echo decodeUnicode(json_encode($a))."\n";?>

参考资料:http://*.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-char

http://php.net/manual/en/function.preg-replace-callback.php