title: How to keep last n number of line from log file in php
body: <p>I want to delete all lines from old log files and keep fresh 50 lines which is at the bottom.</p>
  
  <p>How can I do something like this and if possible can we change the orientation of these lines,</p>
  
  <pre><code>normal input
  
  111111
  2222222
  3333333
  44444444
  5555555
  
  output like
  
  555555
  4444444
  3333333
  22222
  111111
  </code></pre>
  
  <p>To see the fresh log at top and 50 or 100 lines only.</p>
  
  <p>How to join it with this one? </p>
  
  <pre><code>// set source file name and path 
  $source = "toi200686.txt"; 
  // read raw text as array 
  $raw = file($source) or die("Cannot read file"); 
  // join remaining data into string 
  $data = join('', $raw); 
  // replace special characters with HTML entities 
  // replace line breaks with &lt;br /&gt;  
  $html = nl2br(htmlspecialchars($data)); 
  </code></pre>
  
  <p>It made the output as an HTML file. So how will your code run with this?</p>