title: Find and replace word in text file
body: <p>I want to detect if a word in a text file exists, and then remove it.. so, this is my code:</p>
  
  <pre><code>&lt;?php
  $search = $id;
  $lines = file("./user/".$_GET['own'].".txt");
  // Store true when the text is found
  $found = false;
  foreach($lines as $line)
  {
  if(strpos($line, $search) !== false)
  {
  $found = true;
  // open to read and modify
  $file = "./user/".$_GET['own'].".txt";
  $fh = fopen($file, 'r+');
  $data = fread($fh, filesize($file));
  $new_data = str_replace($id."\n", "", $data);
  fclose($fh);
  // Open to write
  $fh = fopen($file, 'r+');
  fwrite($fh, $new_data);
  fclose($fh);
  $status = "has been successfully deleted.";
  }
  }
  // If the text was not found, show a message
  if(!$found)
  {
   $status = "is not exist in your list.";
  }
  ?&gt;
  </code></pre>
  
  <p>I got this work hours before.. I did some changes to my script and somehow, it didnt work anymore.. can anyone see through the code and tell me what is wrong??</p>
  
  <p>or can anybody give simpler way to do what I want?? my code is messed..</p>