1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function raw_json_encode($input, $flags = 0) { $fails = implode('|', array_filter(array( '\\\\', $flags & JSON_HEX_TAG ? 'u003[CE]' : '', $flags & JSON_HEX_AMP ? 'u0026' : '', $flags & JSON_HEX_APOS ? 'u0027' : '', $flags & JSON_HEX_QUOT ? 'u0022' : '', ))); $pattern = "/\\\\(?:(?:$fails)(*SKIP)(*FAIL)|u([0-9a-fA-F]{4}))/"; $callback = function ($m) { return html_entity_decode("&#x$m[1];", ENT_QUOTES, 'UTF-8'); }; return preg_replace_callback($pattern, $callback, json_encode($input, $flags)); } |
Credit : http://stackoverflow.com/questions/16498286/why-does-the-php-json-encode-function-convert-utf-8-strings-to-hexadecimal-entit
0 ความคิดเห็น