Page 1 of 1

Skipping a line (flatfile)

Posted: Sun May 16, 2004 10:21 am
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;

Re: Skipping a line (flatfile)

Posted: Sun May 16, 2004 3:37 pm
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.

Posted: Sun May 16, 2004 4:14 pm
by patrikG
Luxor: don't double post. It's bad for the skin.

Posted: Sun May 16, 2004 6:31 pm
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)