<?php
header('content-type:text/html;charset=utf-8');
if($_POST){
$username = isset($_POST['username'])?$_POST['username']:'';
$content = isset($_POST['content'])?$_POST['content']:'';
$time = time();
$str = $username.'#@#'.$content.'#@#'.$time."\r\n";
file_put_contents('msg.txt', $str,FILE_APPEND);
}
$arr = file('msg.txt');
// print_r($arr);
$list = array();
foreach($arr as $key => $value){
$tmp = explode('#@#',$value);
$list[] = $tmp;
}
// print_r($list);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h2>留言信息</h2>
<table>
<?php foreach($list as $key => $value){?>
<tr>
<td>昵称</td>
<td><span><?php echo $value[0] ?></span></td>
<td>留言时间</td>
<td><span><?php echo date('Y-m-d H:i:s',(int)$value[2]);?></span></td>
</tr>
<tr>
<td>留言内容</td>
<td colspan='3'>
<span><?php echo $value[1] ?></span>
</td>
</tr>
<?php }?>
</table>
<form action="" method="post">
<table>
<tr>
<td>昵称</td>
<td><input type="text" name="username" id=""></td>
</tr>
<tr>
<td>留言信息</td>
<td><textarea name="content" id="" cols="30" rows="10"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>