一个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 相关文章推荐
在Windows中安装Apache2和PHP4的权威指南
Oct 09 PHP
建立文件交换功能的脚本(三)
Oct 09 PHP
php cookie 作用范围?不要在当前页面使用你的cookie
Mar 24 PHP
php 编写安全的代码时容易犯的错误小结
May 20 PHP
php判断输入不超过mysql的varchar字段的长度范围
Jun 24 PHP
PHP数据过滤的方法
Oct 30 PHP
PHP COOKIE及时生效的方法介绍
Feb 14 PHP
yii2使用GridView实现数据全选及批量删除按钮示例
Mar 01 PHP
PHP实现二叉树深度优先遍历(前序、中序、后序)和广度优先遍历(层次)实例详解
Apr 20 PHP
PHP实现字符串的全排列详解
Apr 24 PHP
使用PHPWord生成word文档的方法详解
Jun 06 PHP
thinkphp5 + ajax 使用formdata提交数据(包括文件上传) 后台返回json完整实例
Mar 02 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 XML数据解析代码
2010/05/26 PHP
php字符集转换
2017/01/23 PHP
如何直接访问php实例对象中的private属性详解
2017/10/12 PHP
Laravel框架数据库迁移操作实例详解
2020/04/06 PHP
ie和firefox不兼容的解决方法集合
2009/04/28 Javascript
学习ExtJS table布局
2009/10/08 Javascript
javascript中使用replaceAll()函数实现字符替换的方法
2010/12/25 Javascript
使用Jquery打造最佳用户体验的登录页面的实现代码
2011/07/08 Javascript
jquery下checked取值问题的解决方法
2012/08/09 Javascript
javascript数组排序汇总
2015/07/07 Javascript
JS实现可编辑的后台管理菜单功能【附demo源码下载】
2016/09/13 Javascript
javascript基础知识讲解
2017/01/11 Javascript
jQuery Autocomplete简介_动力节点Java学院整理
2017/07/17 jQuery
详解如何让InstantClick兼容MathJax、百度统计等
2017/09/12 Javascript
vue 通过下拉框组件学习vue中的父子通讯
2017/12/19 Javascript
微信小程序判断用户是否需要再次授权获取个人信息
2019/07/18 Javascript
解决iView Table组件宽度只变大不变小的问题
2020/11/13 Javascript
Python常见数据结构详解
2014/07/24 Python
深入讨论Python函数的参数的默认值所引发的问题的原因
2015/03/30 Python
python处理二进制数据的方法
2015/06/03 Python
python爬虫框架talonspider简单介绍
2017/06/09 Python
Python正则捕获操作示例
2017/08/19 Python
详解配置Django的Celery异步之路踩坑
2018/11/25 Python
python 输出所有大小写字母的方法
2019/01/02 Python
windows python3安装Jupyter Notebooks教程
2020/04/13 Python
Python生成器传参数及返回值原理解析
2020/07/22 Python
css3 box-sizing属性使用参考指南
2013/01/08 HTML / CSS
HOTEL INFO英国:搜索全球酒店
2019/08/08 全球购物
银行见习期自我鉴定
2014/01/29 职场文书
妇联主席先进事迹
2014/05/18 职场文书
企业环保标语
2014/06/10 职场文书
管理岗位竞聘演讲稿
2014/08/18 职场文书
简易离婚协议书范本2014
2014/10/15 职场文书
团员自我评价范文
2015/03/10 职场文书
酒店开业主持词
2015/07/02 职场文书
mysql 乱码 字符集latin1转UTF8
2022/04/19 MySQL