php json_encode unicode decode

WBOY
Release: 2016-06-23 14:36:37
Original
960 people have browsed it

<?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";?>
Copy after login

参考资料: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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template