php maual of json_encode()
http://php.net/manual/en/function.json-encode.php says: All string data of the first input parameter value must be UTF-8 encoded.
Does it really mean that the string data MUST NOT contain any 0x00 byte
(in unicode it may appear)?
I know it will be OK if the input parameter is a valid string encoded in utf-8 . But what about if the input string is a valid GBK-encoded string? Guys, do you know anything about GBK and what I mean?
It means that data must be valid UTF-8. utf8encode function converts ISO-8859-1 to UTF-8, so if you already have that, no need to double-encode it.
A comment on utf8_encode manual page which I believe to be correct:
utf8_encode only converts a string encoded in ISO-8859-1 to UTF-8. A more appropriate name for it would be "iso88591_to_utf8". If your text is not encoded in ISO-8859-1, you do not need this function. If your text is already in UTF-8, you do not need this function. In fact, applying this function to text that is not encoded in ISO-8859-1 will most likely simply garble that text.
So the answer to your question is no, it doesn't mean that. Vice versa. If it is valid UTF-8, then it is ok.
No, it means the string must be valid UTF-8. 0x00
is Unicode character U+0000 and encoded as 0x00
in UTF-8.
php > var_dump(json_encode(["\x00"]));
string(10) "["\u0000"]"