Giorgio Zanetti Giorgio Zanetti - 2 years ago 226
PHP Question

json encoding € symbol

I have a php page generating json extracting values from a mysql table.
Everything is fine except where I have values containing euro symbol (like "€ 20,00") the euro symbol show up in my json as \u20ac...

Like this:

"id": "535",
"Name": "Pluto",
"fare": "\u20ac 20,00"

In the page evaluating this json it appears as "€ 20,00", so this is fine, but I really would like it to appear the same also in the json string itself.

Any hint?

Answer Source

Multibyte can - as long as they are not control characters - be displayed literally or escaped as \uXXXX and both representations are correct. If you prefer the literally representation and if you use php to create the json then you need to pass the correct options to json_encode: Parameters

The option you are looking for is JSON_UNESCAPED_UNICODE:

Encode multibyte Unicode characters literally (default is to escape as \uXXXX). Available since PHP 5.4.0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download