note 113137 deleted from function.json-decode by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 15:00:45 +0000 |
| Subject: | note 113137 deleted from function.json-decode by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215425@lists.php.net to get a copy of this message | ||
Note Submitter: hellolwq at gmail dot com
----
json_decode can not handle string like:\u0014,it will return null,and with the error
<?php json_last_error()=JSON_ERROR_CTRL_CHAR ?>
according ascii_class from json module, use the next codes to fix the bug:
<?php
$str =
preg_replace_callback('/([\x{0000}-\x{0008}]|[\x{000b}-\x{000c}]|[\x{000E}-\x{001F}])/u',
function($sub_match){return '\u00' . dechex(ord($sub_match[1]));},$str);
var_dump(json_decode($str));
?>