How to programmatically implement php method of appending content to txt file

不言
Release: 2023-04-01 12:40:02
Original
1747 people have browsed it

This article mainly introduces the method of appending content to txt files through PHP programming. It involves relevant operating techniques of adding content to txt files by covering PHP, appending content, and reading txt files line by line. Friends who need it can refer to it. Next

The example in this article describes the method of appending content to a txt file through PHP programming. Share it with everyone for your reference, the details are as follows:

Overwrite the txt file content:

$filename="aa/a.txt";
$handle=fopen($filename,"w");
$str=fwrite($handle,"test");
fclose($handle);
Copy after login

Effect:

testtesttesttesttesttesttest
Copy after login

Append content to txt:

$filename="aa/a.txt";
$handle=fopen($filename,"a+");
$str=fwrite($handle,"test\n");
fclose($handle);
Copy after login

Effect:

test
test
test
test
test
test
test
Copy after login

Read txt line by line:

$lines=file("db.txt");
foreach ($lines as $value) {
$line=explode(",",$value);
echo "no1:$line[0]--no2:$line[1]---time:$line[2]-<br>";
}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to implement PHP long URL and short URL

How to implement PHP calling Yunpian.net interface to send Short message

The above is the detailed content of How to programmatically implement php method of appending content to txt file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!