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
dannyd
Forum Commoner
Posts: 56 Joined: Wed Jan 23, 2008 11:31 am
Post
by dannyd » Fri Feb 15, 2008 3:38 pm
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] . ' ' . $fields[2] . ' ' . $fields[3] . '<BR>';
}
}
Thanks!
Last edited by
John Cartwright on Fri Feb 15, 2008 3:47 pm, edited 1 time in total.
Reason: Please use [code=php][/code] tags when posting code!
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Fri Feb 15, 2008 4:07 pm
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] . ' ' . $fields[2] . ' ' . $fields[3] . '<BR>';
}
}