If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.
Post a reply to the thread: PHP file write, add to a file instead of overwrite?
Click here to log in
What is the number after 87?
You may choose an icon for your message from this list
Will turn www.example.com into [URL]http://www.example.com[/URL].
You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.
PHP file write, add to a file instead of overwrite? 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.
PHP file write, add to a file instead of overwrite?
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!
Forum Rules