1个回答
展开全部
<html>
<head>
<title>this is my first php program</title>
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<style type="text/css">
body{
font-family:"黑体";
}
</style>
</head>
<body>
<form method="post" action="two.php">
<table>
<tr><td>user:</td><td><input type="text" name="user" /></td><td>title:</td><td><input type="text" name="title" /></td></tr>
<tr><td>content:</td><td colspan="3"><textarea rows="10" cols="48" name="content"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="submit" /></td><td cols="2"><center><input type="reset" name="reset" value="reset" /></center></td></tr>
</table>
</form>
<hr/>
<?php
$filePath = "message.bak.txt";
if(isset($_POST["submit"])){
$message = $_POST["user"].'<br/>'.$_POST["title"].'<br/>'.$_POST["content"].'<br/>'.time().'<hr/>';
write($filePath,$message);
if(file_exists($filePath)){
$str = read($filePath);
$str = rtrim($str,'<hr/>');
$rows = explode('<hr/>',$str);
foreach($rows as $i){
list($user,$title,$content,$time) = explode('<br/>',$i);
echo '标题:'.$title.' 时间:'.date('Y-m-d H:i:s',$time).'<br/>';
echo '作者:'.$user.'<br/>';
echo $content.'<br/>';
}
}
}
function write($filePath,$message){
$fileResource = fopen($filePath,"a");
if(flock($fileResource,LOCK_EX)){
fwrite($fileResource,$message);
flock($fileResource,LOCK_UN);
}
fclose($fileResource);
}
function read($filePath){
$fileResource = fopen($filePath,"r");
if(flock($fileResource,LOCK_SH)){
$text = fread($fileResource,filesize($filePath));
flock($fileResource,LOCK_UN);
}
fclose($fileResource);
return $text;
}
?>
</body>
</html>
追问
给个完整的代码吧。亲
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询