You will anyway need to call it systematically. So go for it.
Converting Array Values from ISO-8859-1 to UTF8 for JSON Encoding
-
26-06-2022 - |
Pregunta
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))
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow