title: How to get first 3 lines of a file and then everything else
body: <p>I have a txt file like so:</p>
  <blockquote>
  <p>This is line 1.</p>
  <p>This is line 2.</p>
  <p>This is line 3.</p>
  <p>This is the rest.</p>
  <p>Lorem and so on.</p>
  </blockquote>
  <p>I want to use PHP to get the first three lines into a $variable, and then get everything else in the document into a $variable.</p>
  <p>I've had some degree of success with this:</p>
  <pre><code>&lt;?php
  
  $file = fopen(&quot;text.txt&quot;,&quot;r&quot;);
  $count = &quot;0&quot;;
  
  while(! feof($file))
    {
    $count++;
  
    if ($count==&quot;1&quot;) {
    $line1 = fgets($file);
    }
  
    if ($count==&quot;2&quot;) {
    $line2 = fgets($file);
    }
  
    if ($count==&quot;3&quot;) {
    $line3 = fgets($file);
    }
  
  //everything else?
  
  }
  
  echo $line1;
  echo $line2;
  echo $line3;
  //echo $everythingelse;
  
  fclose($file);
  
  ?&gt;
  </code></pre>
  <p>The following works:</p>
  <pre><code>echo fgets($file);
  </code></pre>
  <p>But this doesn't:</p>
  <pre><code>$line1 = fgets($file);
  </code></pre>
  <p>So, A) what am I doing wrong with that, and B) how do I get the rest of the file, and C) is there a better way to implement this? I feel like my way is clumsy and someone'll suggest something obvious which can do all this.</p>
  <p>Thanks guys!</p>