PHP Tutorial Tutorials - PHP File Append

PHP File Append

You can append data into file by using fwrite() function and a or a+ mode in fopen() function.

PHP File Open:Append

If we want to add on to a file we need to open it up in append mode:

<?php
    $handle = fopen("data.txt", "a");
?>

PHP File write: appending data

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
Date:2019-10-01 03:04:02 From:www.Lautturi.com author:Lautturi