Home  >  Article  >  php教程  >  用文本文件制作留言板提示(下)

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

WBOY
WBOYOriginal
2016-06-13 12:40:201094browse

管理你的留言在文本文件中实现不如数据库中那么方便,下面我们想办法来实现这个效果!
在输出的时候我们是用数组来保存数据,那么我们会很方便地为每组数据按顺序分配一个序号,通过对这个序号来操作,我们就可以方便地修改数据!
$date[0]为文本文件中第一行,我们输出时分配序号为0.
输出时有这样的效果:

修改留言
我们再定制modify.php
if($id!=””){
$date=file(“txt/mytxt.txt”);
$str=explode(“&”,$date[0])
?>


  >
>
>
  


}else{
$str=$tech1.”&”. $tech2. ”&”.$tech3….
If($str!=””){
//将修改后的数据写回文本文件!
}
}?>

在这个过程中要注意保持$id的值不丢失,在写回数据时先将文本中的值读入$date,再$date[$id]=$str;
$fp=fopen("txt/mytxt.txt","w");
fwrite($fp,$date);
fclose($fp);
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