|
楼主 |
发表于 2011-5-7 19:56:39
|
显示全部楼层
回复 jeongee 的帖子
嗯
有点明白explode函数了
那不用ci写这个的时候为什么就不报错呢?
<html>
<head>
<title>网络留言板</title>
</head>
<body>
<?php
$filename = "text_data.txt";
if(isset($_POST["sub"]))
{
$message = $_POST["username"]."||".$_POST["title"]."||".$_POST["mess"]."<|>";
$handle = fopen($filename, "a");
flock($handle, LOCK_EX);
fwrite($handle, $message);
flock($handle, LOCK_UN);
fclose($handle);
}
if(file_exists($filename))
{
$handle = fopen($filename, "r");
flock($handle, LOCK_SH);
$buffer.= fread($handle, 1024);
$data = explode('<|>', $buffer);
foreach($data as $line)
{
list($username, $title, $mess) = explode('||', $line);
if($username !=="" && $title !=="" && $mess !=="")
{
echo $username."说:".$mess.'<hr>';
}
}
flock($handle, LOCK_UN);
fclose($handle);
}
?>
<form action="" method="post">
用户名:<input type="text" name="username"><br>
主题:<input type="text" name="title"><br>
<textarea name="mess" rows="10" cols="50">请在这里留言!</textarea>
<input type="submit" name="sub" value="提交">
</form>
</body>
</html> |
|