I use JSON to encode an array, and I get a string like this:
{"name":"\u00fe\u00fd\u00f0\u00f6\u00e7"}
Now I need to convert this to ISO-8859-9. I tried the following but it fails:
header('Content-type: application/json; charset=ISO-8859-9');
$json = json_encode($response);
$json = utf8_decode($json);
$json = mb_convert_encoding($json, "ISO-8859-9", "auto");
echo $json;
It doesnt seem to work. What am I missing?
Thank you for your time.
You can do:
Assuming that strings in
$responseis in utf-8. But I would strongly suggest that you just use utf-8 all the way through.Edit: Sorry, just realised that won’t work, since
json_encodeescapes unicode points as javascript escape codes. You’ll have to convert these to utf-8 sequences first. I don’t think there are any built-in functionality for that, but you can use a slightly modified variation of this library to get there. Try the following: