Page 1 of 1

skip first line

Posted: Fri Feb 15, 2008 3:38 pm
by dannyd
Hi,

How Can I ignore the first line when I'm reading a file. I need it to work with my code below.



Below is the code that goes through the files.

Code: Select all

//parse contents in file
             $file_handle = file_get_contents('./logs/' . $filename);
              // Explodes .txt file into lines (\n)
              $Lines = explode("\n",$file_handle);
 
                  //display fields from file     
                    foreach($Lines as $Line) {
                    
                    $Line = preg_replace('/\s\s+/', ' ', trim($Line));
                    $fields = explode(" ",$Line);
                     
                    echo $fields[1] . '&nbsp;' . $fields[2] . '&nbsp;' . $fields[3] . '<BR>';
      
                   }
 
}
Thanks!

Re: skip first line

Posted: Fri Feb 15, 2008 3:46 pm
by John Cartwright

Code: Select all

$Lines = explode("\n",$file_handle);
array_shift($Lines);

Re: skip first line

Posted: Fri Feb 15, 2008 4:07 pm
by liljester
try the next() function.

Code: Select all

//parse contents in file
$file_handle = file_get_contents('./logs/' . $filename);
// Explodes .txt file into lines (\n)
$Lines = explode("\n",$file_handle);
next($Lines);
//display fields from file 
foreach($Lines as $Line) {
 
$Line = preg_replace('/\s\s+/', ' ', trim($Line));
$fields = explode(" ",$Line);
 
echo $fields[1] . '&nbsp;' . $fields[2] . '&nbsp;' . $fields[3] . '<BR>';
 
}
 
}