title: how to replace some part of text from the text file in php
body: <p>I'm trying to delete/edit some portion of text from text file, like if I have 10 lines in my text file then I want to edit 5th line or delete 3rd line without affecting any other line.</p>
  
  <p>Currently what I'm doing
  1. open text file and read data in php variable
  2. done editing on that variable
  3. delete the content of text file.
  4. write new content on it</p>
  
  <p>but is there any way to doing that thing without deleting whole content or by just edit those content?</p>
  
  <p>my current code is like this</p>
  
  <pre><code>$file = fopen("users.txt", "a+");
  $data = fread($file, filesize("users.txt"));
  fclose($file);
  $newdata = str_replace($old, $new, $data);
  file_put_contents("users.txt", "");
  $file = fopen("users.txt", "a+");
  fwrite($file, $newdata);
  fclose($file);
  </code></pre>