PHP Append to File PHP

PHP Append to File  

PHP Append to File

PHP Append to File

You can append data into file by using a or a+ mode in fopen() function. Let's see a simple example that appends data into data.txt file.

Let's see the data of file first.

data.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

  1. <?php  
  2. $fp = fopen('data.txt', 'a');//opens file in append mode  
  3. fwrite($fp, ' this is additional text ');  
  4. fwrite($fp, 'appending data');  
  5. fclose($fp);  
  6.   
  7. echo "File appended successfully";  
  8. ?>  

Output: data.txt

welcome to php file write this is additional text appending data

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries