title: PHP sscanf doesn't print first line in file but the following lines
body: <p>I have a bunch of files with data formated as follows:
  int|int|string|string</p>
  
  <p>I have some functions to get all files in a directory, format their names and make a select drop-down menu from that.</p>
  
  <p>From that, the user selects the file he wants to open.</p>
  
  <p>The choosen file (its filename) gets send via POST to a second php file that opens in an iframe right below the drop-down form.</p>
  
  <p>These are the relevant contents of said file:</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;A:&lt;/th&gt;
              &lt;th&gt;B:&lt;/th&gt;
              &lt;th&gt;C:&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  &lt;?php
  $fl = $_POST["file"];
  $currentfile = fopen("./dir/$fl","r");
  if ($currentfile) {
      while (($line = fgets($currentfile)) !== false) {
          $n = sscanf($line, "%d|%d|%[^|]|%[^\n]", $a,$b,$c,$d);
          print "&lt;tr&gt;&lt;td&gt;$a&lt;/td&gt;&lt;td&gt;$b&lt;/td&gt;&lt;td&gt;$d&lt;/td&gt;&lt;/tr&gt;";
      }
      fclose($currentfile);
      } else {
          print "Error: Couldn't open file.&lt;br&gt;";
      }
  ?&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Now somehow, the first line in each file isn't shown in the table generated by this, everything else is fine.</p>
  
  <p>As an example, here's one file.</p>
  
  <pre><code>1|334|Item 1
  2|837|Item 2
  3|321|Item 3
  4|124|Item 4
  5|331|Item 5
  
  etc...
  </code></pre>
  
  <p>And this is the output I get.</p>
  
  <pre><code>A:   B:   C:
  
  2    837  Item 2
  3    321  Item 3
  4    124  Item 4
  5    331  Item 5
  
  etc...
  </code></pre>
  
  <p>Or in code:</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;A:&lt;/th&gt;
              &lt;th&gt;B:&lt;/th&gt;
              &lt;th&gt;C:&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;2&lt;/td&gt;
              &lt;td&gt;837&lt;/td&gt;
              &lt;td&gt;Item 2&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;3&lt;/td&gt;
              &lt;td&gt;321&lt;/td&gt;
              &lt;td&gt;Item 3&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;4&lt;/td&gt;
              &lt;td&gt;124&lt;/td&gt;
              &lt;td&gt;Item 4&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;5&lt;/td&gt;
              &lt;td&gt;331&lt;/td&gt;
              &lt;td&gt;Item 5&lt;/td&gt;
          &lt;/tr&gt;
  
          etc...
  
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>So as you can see by above code, the td tags get printed, but there's no data in them, whereas the second set of td tags have the second line of data in them, as it should be, so why doesn't it read, scan and print the first line of the file?</p>