用文本文件制作留言板提示(上)

来源:互联网 发布:shell编程入门 pdf 编辑:程序博客网 时间:2024/06/08 11:39
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
首先是保证文本文件可读写,在文件准备写入之前,我们所要做的是处理好用户留言!
这项工作可以在提交表格前进行,我们将得到的数据各项用特定的符号分开,比如说用&号,值得说明的是如果提交的数据中如果也包含有特定字符,那我们只好将他转化成其他形式,这一点各位自有办法;
如是我们得到数据形如:
$str=”aaaaa&bbbbb&ccccc&ddddd”;
在将数据写入文件前我们加上
$str=$str.”/r/n”

然后执行:
$fp=fopen("txt/mytxt.txt","a");
fwrite($fp,$txt);
fclose($fp);

这样我们写入的数据位于文件末尾部分
如何让最新的留言出现在留言板的首位?
数据有了以上的处理,就好办了,
$date=file(“txt/mytxt.txt”);
$n=count($date);
for ($I=$n;$I>0;$I--){
$str=explode(“&”,$date[$I])
.
//将得到的$str数组各项输出.
.
}

这样最新插入的留言就保持在首位。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击