Is it possible to prevent json_encode from changing the accented characters?

6

I am generating a JSON from a query to the database. When I get the data I store it in an array and then I apply json_encode to create a JSON object.

Everything works fine, but I want to know if it is possible to prevent json_encode from changing the accented characters.

For example, I create data like this:

"antifona": "\u00c1breme los ojos, Se\u00f1or, y contemplar\u00e9 las maravillas de tu voluntad.",
...

I want my data with its accents, because I have validated them, so I do not need json_encode to generate my values like this.

Can you do that in some way? I was reviewing the PHP Manual and I did not see any mention of that possibility.

I would like the following result:

"antifona": "Ábreme los ojos, Señor, y contemplaré las maravillas de tu voluntad.",
...
    
asked by A. Cedano 22.02.2018 в 18:46
source

1 answer

10

It is possible after the version of PHP 5.4 in which to this function is added the parameter "JSON_UNESCAPED_UNICODE" therefore you should have something like this;

json_encode( $mis_datos, JSON_UNESCAPED_UNICODE );

Documentation: link

    
answered by 22.02.2018 / 18:51
source