Append To Files In PHP
If you use a mode, it will not erase the data of the file. It will write the data at the end of the file. Visit the next page to see the example of appending data into a file.
You can append data into a file by using a or a+ mode in fopen() function. Let's see a simple example that appends data into dataFile.txt file.
The data of the file first.
dataFile.txt
welcome to php file write
PHP Append to File - fwrite()
The PHP fwrite() function is used to write and append data into file.
Example
<?php
$fp = fopen("dataFile.txt","a");//opens file in append mode
fwrite($fp, "this is additional text");
fwrite($fp, "appending data");
fclose($fp);
echo "File appended successfully";
?>
Output: dataFile.txt
welcome to php file write this is additional text appending data
Series:
PHP Tutorials Hub
