Reputation: 1920
I have a TXT file and I neede to open it and add a new line at the end. I'm using SplFileObject:
$file = new SplFileObject( $this->fileName, 'w' );
$file->fwrite( 'my text' . PHP_EOL );
But deletes all the file content and only saves 'my text' inside.
Upvotes: 4
Views: 2329
Reputation: 1920
I replaced the 'w' flag to 'a' flag. The 'w' open the file but place the pointer at the beginning, while 'a' place the pointer at the end.
Thanks to @andrewsi for this solution.
Upvotes: 4