我正在尝试发布包括日期在内的两个输入内容,如何获取日期并将其发布到JSON文件中?HTML
PHP
<form method="post" action="go.php">
Name:<input type="text" name="username">
Comment:<input type="text" name="comment">
<input type="submit" value="Submit">
PHP
<?php
$event = $_POST;
$filename = 'data.json';
$handle = @fopen($filename, 'r+');
if ($handle)
{
fseek($handle, 0, SEEK_END);
if (ftell($handle) > 0)
{
fseek($handle, -1, SEEK_END);
fwrite($handle, ',', 1);
fwrite($handle, json_encode($event) . ']');
}
else
{
fwrite($handle, json_encode(array($event)));
}
fclose($handle);
}
?>