title: PHP fwrite() how to insert a new line after some specific line
body: <p>I'm new here.<br>
  Anyway, I did my research on fwrite(), but I couldn't find solution, so i'm asking for help.
  What I want is f.e. to add a new line of text after some other specific line.
  F.e. I have a .txt file in which there is:  </p>
  
  <pre><code>//Users
  
  //Other stuff
  
  //Other stuff2  
  </code></pre>
  
  <p>Now what I'd like to do is be able to add a new user below //Users without touching "Other Stuff" and "Other Stuff 2". So it should look something like this:  </p>
  
  <pre><code>//Users    
  Aneszej  
  Test321  
  Test123
  
  //Other stuff
  
  //Other stuff2  
  </code></pre>
  
  <p>What I have so far:</p>
  
  <pre><code>$config = 'test.txt';
  $file=fopen($config,"r+") or exit("Unable to open file!");
  
  $date = date("F j, Y");
  $time = date("H:i:s");
  
  $username = "user";
  $password = "pass";
  $email = "email";
  $newuser = $username . " " . $password . " " . $email . " " . $date . " " . $time;
  
  while (!feof($file)) {
      $line=fgets($file);
      if (strpos($line, '//Users')!==false) {
          $newline = PHP_EOL . $newuser;
      }
  
  }
  
  fwrite($file, $newline);
  
  fclose($file);
  </code></pre>
  
  <p>test.txt file</p>
  
  <pre><code>//Users
  
  //Something Else
  
  //Something Else 2
  </code></pre>
  
  <p>But this only writes users to the end of the .txt file.  </p>
  
  <p>Thanks a lot everyone for your help! It's solved.</p>