title: PHP write in file in specific location
body: <p>Imagine I have a TXT file with the following contents:</p>
  
  <pre><code>Hello
  How are you
  Paris
  London
  </code></pre>
  
  <p>And I want to write beneath Paris, so Paris has the index of 2, and I want to write in 3.</p>
  
  <p>Currently, I have this:</p>
  
  <pre><code>$fileName = 'file.txt';
  $lineNumber = 3;
  $changeTo = "the changed line\n";
  
  $contents = file($fileName);
  $contents[$lineNumber] = $changeTo;
  
  file_put_contents($fileName, implode('',$contents));
  </code></pre>
  
  <p>But it only modifies the specific line. And I don't want to modify, I want to write a new line and let the others stay where they are.</p>
  
  <p>How can I do this?</p>
  
  <p><strong>Edit</strong>: Solved. In a very easy way:</p>
  
  <pre><code>$contents = file($filename);     
  $contents[2] = $contents[2] . "\n"; // Gives a new line
  file_put_contents($filename, implode('',$contents));
  
  $contents = file($filename);
  $contents[3] = "Nooooooo!\n";
  file_put_contents($filename, implode('',$contents));
  </code></pre>