Page 1 of 1

Delete some lines from a file (till a marker is reached)

Posted: Thu Aug 27, 2009 4:16 pm
by kutchbhi
I have a text file -
This is the title|| some description|| my@email.com ••
another entry|| some other description, but time its really big its so big
infact that it spawns multiple lines|| my@email.com ••
last title|| some description|| my@email.com ••
In this we want to delete from the start of the file, to the marker (••) . Since the marker could be in another line I cannot just delete the first line.

How ?

I found resources to delete the the first line, delete by line number , but nothing for this .
ty

Re: Delete some lines from a file (till a marker is reached)

Posted: Thu Aug 27, 2009 5:29 pm
by jackpf
You mean like this:

Code: Select all

$file = file_get_contents('the_file');
 
$file = explode('••', $file);
 
unset($file[0]);
 
file_put_contents('the_file', implode('••', $file));

Re: Delete some lines from a file (till a marker is reached)

Posted: Thu Aug 27, 2009 6:41 pm
by kutchbhi
works perfectly!
thanks again