留言板共三个文件:
index.php---展示留言内容和收集表单
write.php---向txt文件写入数据
message.txt---存储留言数据
index.php用于展示留言内容、通过表单把用户输入的数据POST给write.php,write.php把内容写入message.txt。
index.php代码:
<?php
//设置时区
date_default_timezone_set('PRC');
//读取内容
@$string=file_get_contents('message.txt');
//如果$string不为空的时候执行,也就是message.txt中有留言数据
if(!empty($string)){
//每一段留言有一个分隔符,但是最后多出了一个&^。因此,我们需要将$^删掉
$string=rtrim($string,'&^');
//以&^切成数组
$arr=explode('&^',$string);
//将留言内容读取
foreach($arr as $value){
list($username,$content,$time)=explode('$#',$value);
echo '用户名:<font color="gree">'.$username.'</font>内容:<font color="red">'.$content.'</font>时间:'.date('Y-m-d H:i:s',$time);
echo '<hr/>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>留言板</title>
</head>
<body>
<h1>

最低0.47元/天 解锁文章
871

被折叠的 条评论
为什么被折叠?



