Skipping a line (flatfile)

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
luxor
Forum Newbie
Posts: 2
Joined: Sun May 16, 2004 10:21 am

Skipping a line (flatfile)

Post by luxor »

Hey :D
Say if my flatfile looks like this...

data1||111||111||111
data2||222||222||222
data3||333||333||333

...and I want to create a function/loop which explodes each lines into variables ( $data[0] = data2, $data[2] = 222, etc.), but I'm not interested in the first line, how would I do that?

Below is my (simplified) old code which works but also lists line one of the flatfile:

Code: Select all

$file = file(flatfile.txt);
foreach($file as $v) 
{
  $info=explode("||",$v);
  print '  <tr>';
  print '    <td>'.$info&#1111;0].'</td>';
  print '    <td>'.$info&#1111;1].'</td>';
  print '    <td>'.$info&#1111;2].'</td>';
  print '    <td>'.$info&#1111;3].'</td>';
  print '  </tr>';
&#125;
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Re: Skipping a line (flatfile)

Post by delorian »

Code: Select all

$file = file(flatfile.txt);
foreach($file as $v) 
&#123;
 if(strlen(trim($v))) &#123;
  $info=explode("||",$v);
  print '  <tr>';
  print '    <td>'.$info&#1111;0].'</td>';
  print '    <td>'.$info&#1111;1].'</td>';
  print '    <td>'.$info&#1111;2].'</td>';
  print '    <td>'.$info&#1111;3].'</td>';
  print '  </tr>';
&#125;
&#125;
This is not a perfect one, but should do the trick.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Luxor: don't double post. It's bad for the skin.
luxor
Forum Newbie
Posts: 2
Joined: Sun May 16, 2004 10:21 am

Post by luxor »

PatrikG: sorry 'bout that one, was kinda desperate earlier on. But i found a solution (different from yours, delorian): i used the array_shift()-function to remove the first chunk in the stack and assign it to another variable (one I'll never use). Thanks for helping, anyways 8)
Post Reply