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
The PHP fwrite() function is used to write and append data into file.
<?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
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning