- If you want to add data on an existing file then you have to open the file in append mode by using fopen function .
$myFile = "append.txt";
$myfilehandle = fopen($myFile, 'a');
File Write:appending data
- Using the write.txt file that we have created in the Chapter File Write , we are going to append on some more data.
$myFile = "write.txt";
$myfilehandle = fopen($myFile, 'a') or die("can't open file");
$stringData = "New Data 1\n";
$stringData = "New Data 2\n";
- You should know that the data we have written to the file is exactly the same as in the Chapter File Write. The only thing that is different is that the file pointer is placed at the end of the file in append mode, so all data is added to the end of the file.
- Now the contents of the file write.txt would look like this:
- Powerful and Efficient.
New Data 1
New Data 2