I want to send some data to browser, I write code like below.
<?php
$arr = array('a'=> "\u0002 hello");
exit(json_encode($arr));
?>
but I wanna a result like below, \u0002 not \\u0002, what should I do?
I want to send some data to browser, I write code like below.
<?php
$arr = array('a'=> "\u0002 hello");
exit(json_encode($arr));
?>
but I wanna a result like below, \u0002 not \\u0002, what should I do?
\u####
is JSON's unicode escape format, and has no meaning in a PHP string.
Using PHP's actual unicode escape:
$arr = array('a'=> "\u{0002} hello");
Or, since codepoints below 128
/ 0x80
have single-byte representations, you can get away with:
$arr = array('a'=> "\x02 hello");
Both will produce the desired output: {"a":"\u0002 hello"}