This question has already been answered:

In the php script, the post method passes a json-like object: {"name":"Иван", "surname":"Иванов"} . Next, you need to write this object to a plain text file. When trying to implement it like this:

 file_put_contents($file, json_encode($obj), FILE_APPEND); 

Similar text is entered into the file instead of Cyrillic:

\ u0418 \ u0432 \ u0430

Solving this problem turned out absolutely inelegant way:

  $file = "file.txt"; $str = '{'; foreach($obj as $key=>$val) { $str.='"'.$key.'":'.'"'.$val.'",'; } $str = preg_replace("/.$/","",$str); $str .= "}\n"; file_put_contents($file, $str, FILE_APPEND); 

The object must be written to the file with curly brackets. All files are UTF8 encoded without BOM. Tell me please, maybe there is some more beautiful and concise way to cope with this task?

Reported as a duplicate by Alex , Spirit of the Community 21 Oct '17 at 20:26 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    Use the special flag of the json_encode() function (see the second example in the documentation

     file_put_contents($file, json_encode($obj, JSON_UNESCAPED_UNICODE), FILE_APPEND); 
    • Thank you so much - Asantasan