Home  >  Article  >  Backend Development  >  用文本文件制作留言板提示(上)_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:29:23696browse

首先是保证文本文件可读写,在文件准备写入之前,我们所要做的是处理好用户留言!
这项工作可以在提交表格前进行,我们将得到的数据各项用特定的符号分开,比如说用&号,值得说明的是如果提交的数据中如果也包含有特定字符,那我们只好将他转化成其他形式,这一点各位自有办法;
如是我们得到数据形如:
$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数组各项输出.
.
}

这样最新插入的留言就保持在首位。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn