首頁 >後端開發 >php教程 >php json_encode unicode decode

php json_encode unicode decode

WBOY
WBOY原創
2016-06-23 14:36:37995瀏覽

<?php$a = array(        'a' => '你好',        '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://stackoverflow.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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:PHP资源下一篇:【转】nginx+php