PHP file write, add to a file instead of overwrite?

Bernz

New member
Yes, you can do it, but you'll need data manipulation (no function does this natively).

If the file is relatively small (< 1 Mb), you can:

- load the entire file into memory (use the file_get_contents() function),
- add the new row at the line you want
- delete the initial file (unlink() function)
- create a new file with the same name (file_put_contents() function)

Good luck!
 
Is it possible?

I am trying to write to a file that already has content in it. Lets say I have file.txt:

------------------------------
First line
second line
last line
----------------------------------

so what if i want to just add something between "second line" and "last line"? Is this at all possible? How can I do this with PHP?

Thanks in advance.
 
Back
Top