Reputation: 48
i'm really new to work with JSON format. I learnd a lot of things - and atm i stuck with the UNICODE-thing. I have a string $str='Läuse';
if I look what charset this string is I use echo mb_detect_encoding($str);
result is UTF-8. Now i create a array and detect again the charset is UTF-8
$json_array = [
'test' => $str
];
echo mb_detect_encoding($json_array['test']);
When I echo the array with json_encode it comes to {"test":"L\u00e4use"}
instead of {"test":"Läuse"}
After searching and reading a lot about php and unicode i'm more and more confused. I learnd that JSON_UNESCAPED_UNICODE will output my json_encode as I want.
My question is, am I doing something wrong that I have to use JSON_UNESCAPED_UNICODE? Do I use the wrong charset ?
Hope you can help me out with that
Upvotes: 0
Views: 45
Reputation: 943615
PHP just defaults to outputting ASCII compatible JSON which is unlikely to be mangled by encoding errors (although it comes at the cost of readability and some bytes).
You aren't doing anything wrong. JSON_UNESCAPED_UNICODE
just is off by default.
Upvotes: 1