Tuesday, July 31, 2012
PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in
PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in
The problem we are seeing is that the value being encoded to json is not UTF-8 encoded data. PHP function json_encode, unfortunately, will only accept UTF-8 as its parameter.
If you search online, you will find that most people solve this problem by using the PHP function utf8_encode. This is fine and dandy if the data you deal with only contains regular alphanumerical characters (letters and numbers), but what if it contains characters from foreign languages? utf8_encode will most certainly return unwanted values, and this is not what you want.
Using utf8_encode is the right idea, but you don’t want to call the function on all your values, just the ones that require it.
better to use utf8_encode($value);
in the latest php version the warning will not come.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment