Managing your messages in a text file is not as convenient as in a database. Let's find a way to achieve this effect!
When outputting, we use arrays to save data, so we can easily assign a serial number to each set of data in order. By operating on this serial number, we can easily modify the data!
$date[0] is the first line in the text file, and the serial number is 0 when we output it.
The output has this effect:
Modify message< ;/a>
Let’s customize modify.php
if($id!=””){
$date=file(“txt/mytxt.txt”);
$str=explode(“& ",$date[0])
?>
}else{
$str=$tech1.”&”. $tech2. ”&”.$tech3….
If($str!=””){
//Write the modified data back to the text file!
}
}?>
In this process, pay attention to keep the value of $id from being lost. When writing back the data, first read the value in the text into $date, and then $date[$id]=$str;
$fp=fopen("txt/mytxt.txt","w");
fwrite($fp,$date);
fclose($fp);
The above introduces the Tianshui Online Mayor Message Board Tips for using text files to create a message board (Part 2), including the content of the Tianshui Online Mayor Message Board. I hope it will be helpful to friends who are interested in PHP tutorials.