How to format REST API display in browser using PHP

0

I'm building a Rest API using PHP.

The data is accented correctly from the database and arrive in the application also correct. The problem is when trying to access the API address through the browser. I want the data, when accessed by the browser, to combine correct accent and indentation.

If I use:

echo json_encode(
    $result, JSON_PRETTY_PRINT
);

The data is shown indented, but the accent is displayed wrong (unicode).

If I use:

echo json_encode(
    $result, JSON_UNESCAPED_UNICODE
);

The data is displayed with the correct accent, but the indentation does not exist (the data is all in a continuous line, making it difficult to read).

Comments:

  • The php file is formatted in utf-8 in the save.
  • The database is MySQL and is also formatted for utf-8.
  • I tried to use header('Content-Type: text/html; charset=utf-8'); and header('Content-Type: application/json; charset=utf-8'); in the PHP file without success.
  • The default server charset is UTF-8, according to phpinfo.

Thank you!

    
asked by anonymous 30.06.2018 / 05:33

0 answers