Invalid Encoding json(显示西里尔文时出现问题)

我正在尝试从表单中推导出一个文件,显示西里尔文时出现问题


PHP (7.1)


<?php

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

    file_put_contents('export.json', json_encode($_REQUEST) );

?>

输出 You_name 字段是用字符写的。


{"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"}



慕雪6442864
浏览 180回答 3
3回答

鸿蒙传说

json_encode( $text, JSON_UNESCAPED_UNICODE );例子:/tmp $ cat test.php<?phpecho 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 --versionPHP 7.3.6 (cli) (built: May 31 2019 23:38:25) ( NTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies&nbsp; &nbsp; with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans&nbsp; &nbsp; with Zend OPcache v7.3.6, Copyright (c) 1999-2018, by Zend Technologies

缥缈止盈

您应该使用 $_POST 来获取表单数据,如下所示&nbsp; header("Content-type: application/json; charset=utf-8");&nbsp; file_put_contents('export.json', json_encode($_POST) );

慕妹3242003

试试这个(来源):header("Content-type: application/json; charset=utf-8")$convert = file_put_contents('export.json', json_encode($_REQUEST));$convert = iconv('CP1251', 'UTF-8', $convert);
打开App,查看更多内容
随时随地看视频慕课网APP