faqts : Computers : Programming : Languages : PHP : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 70 people (37%) answered Yes
Recently 1 of 10 people (10%) answered Yes

Entry

How do I remove a single line from a multi-line text file?

Feb 24th, 2000 08:52
Matt Gregory, Todd Hammer, unknown unknown,


The easiest way to accomplish this is to simply read the entire text 
file into an array using the file(string filename, int 
[use_include_path) function (see php doccumentation).  Once you have 
the entire file in the array, write all the strings you wish to keep 
back out over top of the old file.  Yes, there are other ways to do 
this which are slightly more efficient, but this is the fastest 
implementation and takes the least code.