php - file append
So far we have learned how to open,
close, read, and write to a file. However, the ways in which we have written to
a file so far have caused the data that was stored in the file to be deleted.
If you want to append to a file, that is, add on to the
existing data, then you need to open the file in append mode.
php - file open: append
If we want to add on to a file we need to open it up in append
mode. The code below does just that.
PHP Code:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a');
php - file write: appending data
Using the testFile.txt file we created in the File Write lesson , we are going to append on some more
data.
PHP Code:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't
open file");
$stringData = "New Stuff
1\n";
fwrite($fh, $stringData);
$stringData = "New Stuff
2\n";
fwrite($fh, $stringData);
fclose($fh);
Comments
Post a Comment
Thank you for your Comment