Posted by Toby A Inkster on 04/11/07 09:08
programming wrote:
> say i would like to delete the middle line of this txt, in member.txt
> what php code or logic would help me accomplish this?
For a small file:
1. Read member.txt into an array (the "file" function is
your friend);
2. Make the changes to the array (the "unset" function is
your friend);
3. Output the array to "member-new.txt";
4. Delete "member.txt";
5. Rename "member-new.txt" to "member.txt";
If the file is larger (more than say, 500 kB) this might become a bit
memory-hungry, and it's worth looking at iterating over each line of the
file individually rather than reading it all into memory at once.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|