• Have Any Question?
  • contact@eitworld.com

PHP-File Append





    • 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 1n”;

fwrite($myfilehandle, $stringData);

$stringData = “New Data 2n”;

fwrite($myfilehandle, $stringData);

fclose($myfilehandle);

  • 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:
  • Portable
  • Interactive.
  • Modular.
  • Powerful and Efficient.
Mohan VermaShyam Dua

New Data 1

New Data 2

 



Real Time Web Analytics