I receive a response from a web service, and the values are ISO-8859-1 encoded. The supplied library converts the response to an array, and I am using json_encode to serialize the response and store it in the database. It's a MySQL database, InnoDB engine, with a UTF8 character set.

The encoding issue revealed itself by this warning in my log:

PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in...

I know the array key values are alright because they're always the same and I don't see the warning for every request.

Is there any downside to using array_map with utf8_encode to get rid of the warnings?

json_encode(array_map('utf8_encode', $response))
有帮助吗?

解决方案

You will anyway need to call it systematically. So go for it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top