Home > Article > Backend Development > Use text files to create message board prompts (Part 2)_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, and we assign the sequence number to 0 when outputting.
The output has this effect:
$str=explode("&",$date[0])
?>
}else{
$str=$tech1.”&”. $tech2. ”&”.$tech3….
If($str!=””){
//Write the modified data back to the text file!
}
}?>
Be careful not to lose the value of $id during this process. When writing back the data, first Read the value in the text into $date, then $date[$id]=$str;
$fp=fopen("txt/mytxt.txt","w");
fwrite($fp,$ date);
fclose($fp);