note 110575 deleted from function.json-encode by googleguy
| From: | googleguy@php.net | Date: | Thu, 08 Nov 2012 22:09:25 +0000 |
| Subject: | note 110575 deleted from function.json-encode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191816@lists.php.net to get a copy of this message | ||
Note Submitter: Yuri
----
If you need get unescaped unicode on PHP version < 5.4, you can use this function:
<?php
// For PHP <= 5.3
function utf8_unescape($source){
return preg_replace('/\\\u([0-9A-F]{4})/sei', 'iconv("utf-16",
"utf-8", hex2str("$1"))', $source);
}
function hex2str($hex) {
$r = '';
for ($i = 0; $i < strlen($hex) - 1; $i += 2)
$r .= chr(hexdec($hex[$i] . $hex[$i + 1]));
return $r;
}
// Example
echo utf8_unescape("\u041f\u0440\u0438\u0432\u0435\u0442");
?>