一个php作的文本留言本的例子(五)
程序员文章站
2022-04-20 10:06:59
现在我们来讲一下reply.php的代码: --------------------------------- //reply.php ...
现在我们来讲一下reply.php的代码:
---------------------------------
//reply.php
<?
function check_strlen_long($txt)
{
$len=strlen($txt);
$count=0;
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=60)
{
$txt[$i]="n";
$count=0;
}
}
return $txt;
}
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=stripslashes($txt);
return $message;
}
$content=file("guest.txt");
$disptext=$content[$record-1];
if ($job=="addreply" and $replyname!="" and $replycontent!="")
{
$content=file("guest.txt");
$count=count($content);
$time = date(y年m月d日h小时i分);
$ip=$remote_addr;
$replycontent=stripslashes($replycontent);
$replyname=encode($replyname);
$replycontent=htmlspecialchars($replycontent);
$replycontent=check_strlen_long($replycontent);
$replycontent=nl2br($replycontent);
$replycontent=ereg_replace(chr(10),"",$replycontent);
$content[$record-1]=substr($content[$record-1],0,strlen($content[$i])-1); $content[$record-1]=$content[$record-1]."<!--reply><tr><td colspan=4><ul><font color=#ab00e1>回复内容:</font><br>".$replycontent."<br>回复人大名:".$replyname."<br><font color=#cc33ff>时间:$time 来自:$ip</font></ul><hr size=1 color=blue></td></tr>n";
$fp=fopen("guest.txt","w");
for ($i=0;$i<$count;$i++)
{
fputs($fp,$content[$i],strlen($content[$i]));
}
echo "<meta http-equiv=refresh content=1;url=guest.php>";
exit;
}
?>
<title>zihanonline</title>
<style>
<!--
a:link {text-decoration: none ; color:0000ff}
a:visited {text-decoration: none; color:004080}
a:active {text-decoration: none}
a:hover {text-decoration: underline; color:ff0000}
body {font-size: 10p}
th {font-size: 10pt}
td {font-size: 10pt}
-->
</style>
<body bgcolor="#ffffff" background="back.gif">
<div align=center >
<? include('head.htm');?>
<table border= 1 width= 65% height= 169 cellpadding="8" cellspacing="0" bordercolor="#e3e3e3" >
<form method= post action=reply.php >
<?
if ($submit)
{
if ($replyname=="" or $replycontent=="")
{
echo"<tr align=left valign=middle bgcolor=#f0f0f0> ";
echo"<td width= 100% height= 31 > ";
echo "<font color=red>出错了</font>回复人姓名和回复内容必填!";
echo"</td>";
echo"</tr>";
}
}
?>
<? echo $disptext ?>
<tr align="left" valign="middle" bgcolor="#f0f0f0">
<td width= 100% height= 31 bgcolor="#ffffff" > 回复大名
<input type= text name= replyname size= 20 >
</td>
</tr>
<tr valign="middle">
<td width= 100% height= 26 align= left bgcolor="#f0f0f0" >
<p>回复内容</p>
</td>
</tr>
<tr align="center">
<td width= 100% height= 52 valign= top bgcolor="#ffffff" >
<textarea rows= 6 name= replycontent cols= 46 wrap="virtual" ></textarea>
</td>
</tr>
<tr valign="middle" align="center" bgcolor="#f0f0f0">
<td width= 100% height= 14 bgcolor="#f0f0f0" >
<input type=hidden name=job value=addreply>
<input type=hidden name=record value=<? echo $record ?>>
<input type= submit value= 提交 name=submit >
<input type=reset value= 重写 name= b2 >
</td>
</tr>
</form>
</table>
<?include('bottom.htm');?>
</div>
</body>
</html>
------------------
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看 返回主页
发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续...
---------------------------------
//reply.php
<?
function check_strlen_long($txt)
{
$len=strlen($txt);
$count=0;
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=60)
{
$txt[$i]="n";
$count=0;
}
}
return $txt;
}
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=stripslashes($txt);
return $message;
}
$content=file("guest.txt");
$disptext=$content[$record-1];
if ($job=="addreply" and $replyname!="" and $replycontent!="")
{
$content=file("guest.txt");
$count=count($content);
$time = date(y年m月d日h小时i分);
$ip=$remote_addr;
$replycontent=stripslashes($replycontent);
$replyname=encode($replyname);
$replycontent=htmlspecialchars($replycontent);
$replycontent=check_strlen_long($replycontent);
$replycontent=nl2br($replycontent);
$replycontent=ereg_replace(chr(10),"",$replycontent);
$content[$record-1]=substr($content[$record-1],0,strlen($content[$i])-1); $content[$record-1]=$content[$record-1]."<!--reply><tr><td colspan=4><ul><font color=#ab00e1>回复内容:</font><br>".$replycontent."<br>回复人大名:".$replyname."<br><font color=#cc33ff>时间:$time 来自:$ip</font></ul><hr size=1 color=blue></td></tr>n";
$fp=fopen("guest.txt","w");
for ($i=0;$i<$count;$i++)
{
fputs($fp,$content[$i],strlen($content[$i]));
}
echo "<meta http-equiv=refresh content=1;url=guest.php>";
exit;
}
?>
<title>zihanonline</title>
<style>
<!--
a:link {text-decoration: none ; color:0000ff}
a:visited {text-decoration: none; color:004080}
a:active {text-decoration: none}
a:hover {text-decoration: underline; color:ff0000}
body {font-size: 10p}
th {font-size: 10pt}
td {font-size: 10pt}
-->
</style>
<body bgcolor="#ffffff" background="back.gif">
<div align=center >
<? include('head.htm');?>
<table border= 1 width= 65% height= 169 cellpadding="8" cellspacing="0" bordercolor="#e3e3e3" >
<form method= post action=reply.php >
<?
if ($submit)
{
if ($replyname=="" or $replycontent=="")
{
echo"<tr align=left valign=middle bgcolor=#f0f0f0> ";
echo"<td width= 100% height= 31 > ";
echo "<font color=red>出错了</font>回复人姓名和回复内容必填!";
echo"</td>";
echo"</tr>";
}
}
?>
<? echo $disptext ?>
<tr align="left" valign="middle" bgcolor="#f0f0f0">
<td width= 100% height= 31 bgcolor="#ffffff" > 回复大名
<input type= text name= replyname size= 20 >
</td>
</tr>
<tr valign="middle">
<td width= 100% height= 26 align= left bgcolor="#f0f0f0" >
<p>回复内容</p>
</td>
</tr>
<tr align="center">
<td width= 100% height= 52 valign= top bgcolor="#ffffff" >
<textarea rows= 6 name= replycontent cols= 46 wrap="virtual" ></textarea>
</td>
</tr>
<tr valign="middle" align="center" bgcolor="#f0f0f0">
<td width= 100% height= 14 bgcolor="#f0f0f0" >
<input type=hidden name=job value=addreply>
<input type=hidden name=record value=<? echo $record ?>>
<input type= submit value= 提交 name=submit >
<input type=reset value= 重写 name= b2 >
</td>
</tr>
</form>
</table>
<?include('bottom.htm');?>
</div>
</body>
</html>
------------------
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看 返回主页
发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续...