title: PHP file write - max lines
body: <p>How to put a limit for writing in a file, if it hit the limit then remove the last line..</p>
  
  <p>As example here's a file:</p>
  
  <pre><code>Line 3
  Line 2
  Line 1
  </code></pre>
  
  <p>i want to max line it for 3 lines only.. so when i write a new line using any append functions it removes the last line.. Let's say i just wrote a new line ( Line 4 ).. so it goes to the last one and remove it, result should be :</p>
  
  <pre><code>Line 4
  Line 3
  Line 2
  </code></pre>
  
  <p>And for a new written line (Line 5):</p>
  
  <pre><code>Line 5
  Line 4
  Line 3
  </code></pre>
  
  <p>numeric lines is not required, i just want to remove the last line if there's a new added line via an append functions <i>(file_put_contents / fwrite)</i> and max it by 3 or a specific number i give</p>