Home >Backend Development >PHP Tutorial >Tips on creating a message board using text files_PHP tutorial
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 will 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. When we output, the serial number is assigned to 0.
The output has this effect:
Modify the message
We will customize the 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");