Reputation: 22969
I have a Japanese string in my (UTF-8 encoded) database '利用規約' which is passed to php's json_encode function and receive this warning:
PHP Warning: json_encode(): Invalid UTF-8 sequence in argument
Is there a way to convert this to valid UTF-8 in order to avoid this? If the db is utf-8 why would php have a problem with the string?
Update:
Turns out the error was in fact due to a problem with sprintf and multibyte characters a couple lines earlier.
Upvotes: 3
Views: 9890
Reputation: 156
utf8_encode only works with ISO-8859-1 (see language coverage here wikip)
you should try mb_convert_encoding() php encoding doc
:)
Upvotes: 2
Reputation: 35357
utf8_encode should work for you.
http://www.php.net/manual/en/function.utf8-encode.php
If utf8_encode doesn't work, try mb_convert_encoding:
mb_convert_encoding($string,"UTF-8","auto");
Upvotes: 9