Page 1 of 1

Remove lines from file

Posted: Thu Mar 11, 2010 3:17 am
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!

Re: Remove lines from file

Posted: Thu Mar 11, 2010 3:42 am
by Grizzzzzzzzzz
the first result on google when searching for "php delete by line number":

http://www.phpro.org/examples/Delete-Li ... -File.html

Re: Remove lines from file

Posted: Thu Mar 11, 2010 3:46 am
by dragosa
I know this script
but this script delete only one line
I need to delete multiple line ( eg. line 91, 67, 98...)

Re: Remove lines from file

Posted: Thu Mar 11, 2010 4:44 am
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++;
    }
 

Re: Remove lines from file

Posted: Fri Mar 12, 2010 2:31 pm
by dragosa
is work..thank you