note 102850 deleted from function.json-encode by danbrown

From: Date: Thu, 10 Mar 2011 15:19:15 +0000
Subject: note 102850 deleted from function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177751@lists.php.net to get a copy of this message
Note Submitter: Mathias Leppich ---- 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

« previous php.notes (#177751) next »