Home >Backend Development >PHP Tutorial >Using text files to create message board prompts (Part 1)_PHP tutorial

Using text files to create message board prompts (Part 1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:04:35768browse

The first thing is to ensure that the text file can be read and written. Before the file is ready to be written, all we have to do is to process the user's message!
This work can be done before submitting the form. We will separate the data items obtained with specific symbols, such as ampersands. It is worth mentioning that if the submitted data also contains specific characters, then we We have to convert it into other forms, and you have your own way;
In this way, we get the data in the form:
$str=”aaaaa&bbbbb&ccccc&ddddd”;
Before writing the data to the file, we add
$str=$str.”rn”

Then execute:
$fp=fopen("txt/mytxt.txt","a");
fwrite($fp,$txt );
fclose($fp);

In this way, the data we write is at the end of the file
How to make the latest message appear at the top of the message board?
With the above processing, the data will be easy to handle,
$date=file(“txt/mytxt.txt”);
$n=count($date);
for ($ I=$n;$I>0;$I--){
$str=explode(“&”,$date[$I])
.
//The $str array that will be obtained Various outputs.
.
}

This way the latest inserted message will remain at the top.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315934.htmlTechArticleThe first thing is to ensure that the text file is readable and writable. Before the file is ready to be written, what we have to do is to handle the user message! This work can be done before submitting the form and the data we will get...
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