IncreMan IncreMan - 26 days ago 8
JSON Question

Inserting JSON string into MySQL column UTF-8

I am generating JSON valid string like:

[{"head":"Model Name","body":"T102HA-GR015T"}]


The string generated on UTF-8 page with
header('Content-Type: text/html; charset=utf-8');
and file encoding UTF-8.

The connection to database made by PDO with
charset=utf8


DB table & column collations are
utf8_general_ci


When it inserted to db it look like:

For Russian:
[{"head":"\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438","body":"T102HA-GR015T"}]


For Hebrew:
[{"head":"\u05d3\u05d2\u05dd","body":"T102HA-GR015T"}]


And I want it to be inserted to db in actual lang characters, like:

For Russian:
[{"head":"Название модели","body":"T102HA-GR015T"}]


For Hebrew:
[{"head":"דגם","body":"T102HA-GR015T"}]


phpMyAdmin screenshot:
enter image description here

Answer Source

Thanks to @RickJames for helping, solved using JSON_UNESCAPED_UNICODE

$array = json_encode($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)