1

I am trying to deduce a file from the form, I have a problem when displaying Cyrillic

Php (7.1)

<?php
    header("Content-type: application/json; charset=utf-8");
    file_put_contents('export.json', json_encode($_REQUEST) );
?>

Output You_name field is written in characters.

{"Entry_ID":"71","You_name":"\u041a\u043e\u0437\u043b\u0430\u043d\u0431\u0435\u043a \u0410\u043c\u0438\u0440 \u041f\u043e\u043c\u0438\u0434\u043e\u0440\u043e\u0432\u0438\u0447","You_phone":"7 (902) 998 1019","You_date":"19\/06\/2019"}
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39

3 Answers3

1

6 year old answer still stands: Why does the PHP json_encode function convert UTF-8 strings to hexadecimal entities?

json_encode( $text, JSON_UNESCAPED_UNICODE );

Example:

/tmp $ cat test.php
<?php
echo json_encode(['key'=>'ыфва']), PHP_EOL;
echo json_encode(['key'=>'ыфва'], JSON_UNESCAPED_UNICODE), PHP_EOL;
/tmp $ php test.php
{"key":"\u044b\u0444\u0432\u0430"}
{"key":"ыфва"}
/tmp $ php --version
PHP 7.3.6 (cli) (built: May 31 2019 23:38:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.3.6, Copyright (c) 1999-2018, by Zend Technologies
alx
  • 2,314
  • 2
  • 18
  • 22
0

You should use $_POST to get the form data like as below

  header("Content-type: application/json; charset=utf-8");

  file_put_contents('export.json', json_encode($_POST) );
Devendra Rajput
  • 432
  • 7
  • 13
0

Try this (source) :

header("Content-type: application/json; charset=utf-8")

$convert = file_put_contents('export.json', json_encode($_REQUEST));
$convert = iconv('CP1251', 'UTF-8', $convert);
MushuLeDragon
  • 87
  • 2
  • 12