一个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].!–replytrtd colspan=4ulfont
color=#AB00E1回复内容:/fontbr.$replycontent.br回复人大名:.$replyname.brfont
color=#CC33FF时间:$time 来自:$ip/font/ulhr size=1 color=blue/td/trn;
$fp=fopen(guest.txt,w); for ($i=0;$i$count;$i++) {
fputs($fp,$content[$i],strlen($content[$i])); } echo meta
content=1;url=guest.php; exit; } ?titlezihanonline/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 ? include(‘head.htm’);? table
border= 1width= 65%height= 169 cellpadding=8 cellspacing=0
bordercolor=#E3E3E3 form method= POSTaction=reply.php ? if ($Submit) {
if ($replyname== or $replycontent==) { echotr align=left valign=middle
bgcolor=#F0F0F0 ; echotd width= 100%height= 31 ; echo font
color=red出错了/font回复人姓名和回复内容必填!; echo/td; echo/tr; } } ? ?
echo $disptext ?tr align=left valign=middle bgcolor=#F0F0F0td width=
100%height= 31 bgcolor=#FFFFFF 回复大名input type= textname=
replynamesize= 20 /td /tr tr valign=middletd width= 100%height= 26align=
left bgcolor=#f0f0f0 p回复内容/p /td /tr tr align=centertd width=
100%height= 52valign= top bgcolor=#FFFFFF textarea rows= 6name=
replycontentcols= 46 wrap=VIRTUAL /textarea /td /tr tr valign=middle
align=center bgcolor=#F0F0F0td 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 input
type=reset value= 重写name= B2 /td /tr /form
/table?include(‘bottom.htm’);?/div /body /html ——————
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看
返回主页发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续…

这一节我们将dele.php和sys.php放上来. ——— //dele.phphtml head
title删除留言/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:10pt} TH {FONT-SIZE:10 pt} TD {FONT-SIZE:
10pt} — /style meta content=text/html; charset=gb2312 /head ?
require(sys.php); if ($Submit) { if ($password$managepwd) {$errorm=font
color=red密码错误/font.无权操作..;} else{ $content=file($guestfile);
$message=$content[$record-1]; $count=count($content); if
($dele==delreply) { $replylen=strlen(strstr($message,!–reply));
$long=strlen($message); $len=$long-$replylen;
$message=substr($message,0,$len); } else {$message=;} //writefile
$fp=fopen($guestfile,w); for ($i=0;$i$count;$i++) { if
($i==($record-1)){$content[$i]=$message;}
fputs($fp,$content[$i],strlen($content[$i])); }//end for
fclose($fp); echo meta content=1;url=guest.php; exit; } }// end ifSubmit
$content=file($guestfile); $message=$content[$record-1];
$found=ereg(!–reply,$message); ? body bgcolor=#FFFFFF
background=back.gif ? include(head.htm); ? table width=68% border=1
cellpadding=5 align=center cellspacing=0 bordercolor=#F2F2F2 form
action=dele.php method=post ? if ($errorm) { echo tr; echo td
height=27$errorm/td; echo /tr; } ? ? echo $message ? tr align=centertd
height=37 bgcolor=#f0f0f0? if ($found) { echo input type=radio
name=dele value=delall; echo 全部删除 ; echo input type=radio name=dele
value=delreply checked; echo 仅删除回复; } ? font
color=#000000管理密码/fontinput type=password name=password size=10
input type=hidden name=record value=? echo $record;? input type=submit
name=Submit value=我要删除了 /td /tr /form /table ? include(bottom.htm);
? /body /html —— //sys.php titlezihanonline/title?
$managepwd=’zihanonline’; $guestfile=guest.txt; function
check_strlen_long($txt) { $count=0; $arrtemp=$txt; $len=strlen($txt);
$txt=$txt.”; 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=70){ for ($j=$i;$j$len;$j++) {
$txt[$j+1]=$arrtemp[$j]; } $txt[$i]=n; $len=$len+1;
$txt[$len]=$arrtemp[$len-1]; $count=0; $arrtemp=$txt; }//end if
count } $txt=trim($txt); return $txt; }//end function function encode
($txt) { $txt=strip_tags($txt); $txt=htmlspecialchars($txt);
$message=StripSlashes($txt); return $message; } function ubb($txt) { } ?
body bgcolor=#FFFFFF background=back.gif ———- 注意sys.php中的
$managepwd=’zihanonline’
一栏中等号后的是留言本的管理密码号,此时是默认的zihanonline.您可以修改为自己的号码.
未完待续…