如何删除JSON方括号和双引号


How can I remove JSON brackets and double quotes?

我正在用PHP编写一个点击计数器的日志文件。每次用户单击按钮时的数据(日期、时间等)都指向data.json文件。我想把这些数据放在logfile.txt中,但当我使用file_get_contents时,括号和引号也会被转移,这使得日志文件更难理解。有没有办法不包括括号和引号?

$txtlog = '../Logfile-'.date('mdY').'.txt';
$mytxt = fopen($txtlog, "a") or die("<br/>Unable to open file!");
fwrite($mytxt, file_get_contents("DATA.json"));
fclose($mytxt);

看看json_decode()。在文件中使用它,它将返回一个索引为"date"answers"time"的数组。只需对其进行迭代,就可以管理日志

使用此json_decode("DATA.json")