How to json_encode array with french accents?

Viewed 54962

I have an array item with a French accent ([WIPDescription] => Recette Soupe à lOignon Sans Boeuf US). The data is being properly pulled from the database (mysql).

However, when I try to encode this as json using the php built in json_encode it produces a null json value (OS X server: php 5.3.4, json 1.2.1 enabled).

In a Linux server, the description is cut off after the first accent character.

I tried all the json_encode options with no success. Any suggestions?

Thank you.

7 Answers

If you deal with diacritics you can also add JSON_PARTIAL_OUTPUT_ON_ERROR and it will remove only the problems and leave the rest intact. I used utf_encode before I found this but it was messing up diacritics.

echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
Related