note 102850 added to function.json-encode
| From: | MathiasLeppich at osu1 dot php dot net | Date: | Thu, 10 Mar 2011 09:04:04 +0000 |
| Subject: | note 102850 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177732@lists.php.net to get a copy of this message | ||
If you want 'real' unicode characters instead of escape sequences in your json:
<?php
function json_encode_unicode($data) {
return str_replace("&&","&",
html_entity_decode(
preg_replace(
'/(?<!\\\\)\\\\u([0-9a-f]{4})/u',
'&#x\\1;',
str_replace("&","&&",
json_encode($data)
)
),
ENT_NOQUOTES,
'UTF-8'
)
);
}
/*
returns
{
"chinese":"æ±è¯\/æ¼¢èª Hanyu; åè¯\/è¯èª
HuáyÇ; 䏿 ZhÅngwén",
"korean":"íêµì´\/ì¡°ì ë§",
"japanese":"æ¥æ¬èª Nihongo"
}
rather than
{
"chinese":"\u6c49\u8bed\/\u6f22\u8a9e Hanyu; \u534e\u8bed\/\u83ef\u8a9e
Hu\u00e1y\u01d4; \u4e2d\u6587 Zh\u014dngw\u00e9n",
"korean":"\ud55c\uad6d\uc5b4\/\uc870\uc120\ub9d0",
"japanese":"\u65e5\u672c\u8a9e Nihongo"
}
*/
?>
see http://gist.github.com/863757 for more details
----
Server IP: 69.147.83.197
Probable Submitter: 79.246.63.52
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/102850
Del: integrated -- https://master.php.net/note/delete/102850/integrated
Del: useless -- https://master.php.net/note/delete/102850/useless
Del: bad code -- https://master.php.net/note/delete/102850/bad+code
Del: spam -- https://master.php.net/note/delete/102850/spam
Del: non-english -- https://master.php.net/note/delete/102850/non-english
Del: in docs -- https://master.php.net/note/delete/102850/in+docs
Del: other reasons-- https://master.php.net/note/delete/102850
Reject -- https://master.php.net/note/reject/102850
Search -- https://master.php.net/manage/user-notes.php