Understanding what \u0000 is in PHP / JSON and getting rid of it

\uXXXX is the JSON Unicode escape notation (X is hexadecimal).

In this case, it means the 0 ASCII char, aka the NUL byte, to split it you can either do:

explode('\u0000', json_encode($array[0]));

Or better yet:

explode("\0", $array[0]); // PHP doesn't use the same notation as JSON

The string you have is "hello\0world", or "hello\x00world" whatever you prefer. If you echo it, the null symbol \0 won't be displayed, thats why you see helloworld instead, but json_encode will detect it and escape it as it does to any other special character, thats why its replaced by a visible \u0000 string.

In my way of seeing it, json is encoding the string perfectly, the \u0000 is there to do its job of reproducing the inputted string in a json encoded way. You don't have to touch its output. If you don't want that \u0000 there you should fix its input instead.


you can simply do trim($str) without giving it a charlist

Tags:

Php

Json