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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kutchbhi
Forum Newbie
Posts: 12
Joined: Mon Aug 24, 2009 2:00 pm

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

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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));
kutchbhi
Forum Newbie
Posts: 12
Joined: Mon Aug 24, 2009 2:00 pm

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

Post by kutchbhi »

works perfectly!
thanks again
Post Reply