You can append data into file by using fwrite() function and a or a+ mode in fopen() function.
If we want to add on to a file we need to open it up in append mode:
<?php
$handle = fopen("data.txt", "a");
?>
data.txt
PHP append data to file example.
<?php
$handle = fopen("data.txt", "a"); // open file in append mode
fwrite($handle, ' appending data 1 ');
fwrite($handle, ' appending data 2');
fclose($handle);
echo "File appended successfully";
?>
It would write data at the end of the file:
``` plain
PHP append data to file example. appending data 1 appending data 2
