How to json_encode array with french accents?

后端 未结 7 2290
离开以前
离开以前 2020-12-05 13:58

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).

7条回答
  •  -上瘾入骨i
    2020-12-05 14:02

    I found this to be the easiest way to deal with it

    echo json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    

    JSON_PRETTY_PRINT - makes is readable
    JSON_UNESCAPED_UNICODE - encodes characters correctly
    JSON_UNESCAPED_SLASHES - gets rid of escape slash '\'
    also notice that these option are separated by a pipe '|'

提交回复
热议问题