Remove lines from file

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
dragosa
Forum Newbie
Posts: 3
Joined: Thu Mar 11, 2010 3:09 am

Remove lines from file

Post by dragosa »

Hi all,
Sombody know a php script how eraise a specific lines from file
(e.g. i want to delete the lines from line 91 to line 100 from test.txt)
I searched on Google and found a script that delete only one line. i need to eraise multiple line (specific line)
Thank you!
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: Remove lines from file

Post by Grizzzzzzzzzz »

the first result on google when searching for "php delete by line number":

http://www.phpro.org/examples/Delete-Li ... -File.html
dragosa
Forum Newbie
Posts: 3
Joined: Thu Mar 11, 2010 3:09 am

Re: Remove lines from file

Post by dragosa »

I know this script
but this script delete only one line
I need to delete multiple line ( eg. line 91, 67, 98...)
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: Remove lines from file

Post by Grizzzzzzzzzz »

put a loop into it?

eg:

Code: Select all

 
$linesToDelete = array("1","2","3");
    
    $i = 0;
    while($linesToDelete[$i])
    {
        delLineFromFile($fileName, $linesToDelete[$i]);
        $i++;
    }
 
dragosa
Forum Newbie
Posts: 3
Joined: Thu Mar 11, 2010 3:09 am

Re: Remove lines from file

Post by dragosa »

is work..thank you
Post Reply