Home >Backend Development >PHP Tutorial >PHP programming method to append content to txt file

PHP programming method to append content to txt file

不言
不言Original
2018-04-26 14:15:072044browse

This article mainly introduces the method of appending content to txt files through PHP programming. It involves PHP overlay adding content to txt files, appending content, and related operation skills of reading txt files line by line. Friends in need 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);

Effect:

testtesttesttesttesttesttest

Append content to txt:

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

Effect:

test
test
test
test
test
test
test

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>";
}

Related recommendations:

The functions of TCP server and client implemented by PHP programming

Detailed explanation of PHP programming to realize WeChat enterprise payment method to users

Example introduction to PHP programming to realize the conversion of solar calendar to lunar calendar

The above is the detailed content of PHP programming method to append content to txt file. For more information, please follow other related articles on the PHP Chinese website!

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