一个php作的文本留言本的例子(五)


Posted in PHP onOctober 09, 2006

现在我们来讲一下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的建立和上传留言本的几个重要步骤.
未完待续...

PHP 相关文章推荐
PHP网站提速三大“软”招
Oct 09 PHP
PHP4 与 MySQL 数据库操作函数详解
Dec 06 PHP
解析php中die(),exit(),return的区别
Jun 20 PHP
基于PHP magic_quotes_gpc的使用方法详解
Jun 24 PHP
PHP系统命令函数使用分析
Jul 05 PHP
利用谷歌 Translate API制作自己的翻译脚本
Jun 04 PHP
PHP反射机制用法实例
Aug 28 PHP
详解PHP的Laravel框架中Eloquent对象关系映射使用
Feb 26 PHP
浅谈PHP的$_SERVER[SERVER_NAME]
Feb 04 PHP
PHP数字前补0的自带函数sprintf 和number_format的用法(详解)
Feb 06 PHP
ThinkPHP实现转换数据库查询结果数据到对应类型的方法
Nov 16 PHP
php快速导入大量数据的实例方法
Sep 23 PHP
一个php作的文本留言本的例子(一)
Oct 09 #PHP
PHP的类 功能齐全的发送邮件类
Oct 09 #PHP
以文本方式上传二进制文件的PHP程序
Oct 09 #PHP
用户的详细注册和判断
Oct 09 #PHP
PHP编程与应用
Oct 09 #PHP
谈谈PHP语法(2)
Oct 09 #PHP
无数据库的详细域名查询程序PHP版(1)
Oct 09 #PHP
You might like
PHP与MySQL开发中页面乱码的产生与解决
2008/03/27 PHP
关于IIS php调用com组件的权限问题
2012/01/11 PHP
php获取中文拼音首字母类和函数分享
2014/04/24 PHP
常见PHP数据库解决方案分析介绍
2015/09/24 PHP
IE 当eval遇上function的处理
2011/08/09 Javascript
Javascript的各种节点操作实例演示代码
2012/06/27 Javascript
JS常用正则表达式总结
2013/11/12 Javascript
jQuery.parseJSON(json)将JSON字符串转换成js对象
2014/07/27 Javascript
js实现完全自定义可带多级目录的网页鼠标右键菜单方法
2015/02/28 Javascript
JS文字球状放大效果代码分享
2015/08/19 Javascript
JS Array.slice 截取数组的实现方法
2016/01/02 Javascript
超实用的javascript时间处理总结
2016/08/16 Javascript
Angular企业级开发——MVC之控制器详解
2017/02/20 Javascript
Nuxt项目支持eslint+pritter+typescript的实现
2019/05/20 Javascript
Vue请求java服务端并返回数据代码实例
2019/11/28 Javascript
python好玩的项目—色情图片识别代码分享
2017/11/07 Python
Python扩展内置类型详解
2018/03/26 Python
解决python中无法自动补全代码的问题
2018/12/04 Python
打包PyQt5应用时的注意事项
2020/02/14 Python
python 实现倒计时功能(gui界面)
2020/11/11 Python
意大利奢华内衣制造商:Cosabella
2017/08/29 全球购物
英国水族馆和池塘用品购物网站:Warehouse Aquatics
2019/08/29 全球购物
美国领先的宠物用品和宠物食品零售商:Petco
2020/10/28 全球购物
幼儿园中班下学期评语
2014/04/18 职场文书
文明村镇申报材料
2014/05/06 职场文书
2014年秘书工作总结
2014/11/25 职场文书
民事诉讼代理词
2015/05/25 职场文书
女性健康知识讲座主持词
2015/07/04 职场文书
环境卫生整治简报
2015/07/20 职场文书
2015初中政治教学工作总结
2015/07/21 职场文书
银行求职信怎么写
2019/06/20 职场文书
一个成功的互联网创业项目,必须满足这些要求
2019/08/23 职场文书
导游词之上海杜莎夫人蜡像馆
2019/11/22 职场文书
SQL实现LeetCode(180.连续的数字)
2021/08/04 MySQL
Go语言的协程上下文的几个方法和用法
2022/04/11 Golang
Mysql如何查看是否使用到索引
2022/12/24 MySQL