Reply to Re: deleting a line

Your name:

Reply:


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!

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация