一个php作的文本留言本的例子(五)_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= 2width= 65%height= 169 cellpadding="8" cellspacing="0" bordercolor="#E3E3E3" >
<form method= POSTaction=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= textname= replynamesize= 20 >
</td>
</tr>
<tr valign="middle">
<td width= 100%height= 26align= left bgcolor="#f0f0f0" >
<p>回应內容</p>
</td>
</tr>
<tr align="center">
<td width= 100%height= 52valign= top bgcolor="#FFFFFF" >
<textarea rows= 6name= replycontentcols= 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= submitvalue= 递交name=Submit >
&nbsp;&nbsp;&nbsp;
<input type=reset value= 调用name= B2 >
</td>
</tr>
</form>
</table>
<?include(bottom.htm);?>
</div>
</body>
</html>
——————
到这里,php的代码大家早已写完,剩余的是您要作一个留言本的本头和底端
您能够设计方案一切的款式.但是还记得在本头上边要有最少3个联接:查询 返回首页
发送邮件.那样您的留言本系统软件才算详细.但是因为它是一文本的留言本,因此 您担心数据库查询的难题,您要是再写一个guest.txt的文档就详细了.尽管这一留言本沒有mysql这些,但是作用依然非常好.并且是彻底归属于您自身的留言本.好啦,下一节大家将为您叙述guest.txt的创建和提交留言本的好多个关键流程.
未完待续…

原创文章,作者:娜娜,如若转载,请注明出处:https://na.wang/zx/web/php/9064.html