Home >Backend Development >PHP Tutorial >How to add content to txt file in php
This article mainly introduces the method of appending content to txt files in PHP, involving related operating techniques of adding content to PHP overlay to Txt files, appending content and reading Txt files line by line. Friends in need can refer to the following
The details are as follows:
Overwrite the content of the txt file:
$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:
PHP programming method to append content to a txt file
PHP uses the built-in function file_put_contents to write files and Append contentmethod_PHP
PHP uses the built-in function file_put_contentsWrite files and Append contentmethods_php skills
The above is the detailed content of How to add content to txt file in php. For more information, please follow other related articles on the PHP Chinese website!