title: Remove line of file1 that exist on file2
body: <p>I want remove all line present on FILE1 from the FILE2.</p>
  
  <p>I tried using this code, but didn't succeeded:</p>
  
  <p><em>The function:</em></p>
  
  <pre><code>function removeit($searchfor, $file) {
     $file1 = fopen($file, "r") or exit("Unable to openfile!");
     $t="";
     while(!feof($file1)) {
        $k= fgets($file1);
        $pattern = preg_quote($searchfor, '/');
        $pattern = "/^.*$pattern.*\$/m";
        if ( preg_match($pattern, $k))
        {}
        else {
           $t=$t.$k;
        }
     }
  
     fclose($file1);
     $file = fopen($file, "w") or exit("Unable to open file!");
     fwrite($file,$t);
     fclose($file);
  }
  </code></pre>
  
  <p><em>The code that do the job:</em></p>
  
  <pre><code>$file = fopen("file1.txt", "r");
  while(!feof($file)) {
     $line = fgets($file);
     # do same stuff with the $line
     echo removeit(trim($line), 'file2.txt');
  }
  fclose($file);
  </code></pre>
  
  <p>Please any fix for this code ? or do you have any other method to do this job properly ?
  I tried all sort of code in order to get the proper result, but all what i tried was not succeeded.</p>
  
  <p>The lines of FILE1 present on FILE2 not contained on a full line !</p>
  
  <p><strong><em>Here an example:</em></strong></p>
  
  <p><em>FILE1:</em></p>
  
  <pre><code>AAA
  BBB
  CCC
  DDD
  </code></pre>
  
  <p><em>And here FILE2:</em></p>
  
  <pre><code>555AAAPPP // This line contain AAA line1 of FILE1 (To remove)
  MMMBBBEEE // This contain BBB (To remove)
  111CCC333 // This contain CCC (To remove)
  DD15568 // This line will not be removed because not present on FILE1
  </code></pre>
  
  <p>And the code must let the code stay like it was before, only lines must be removed.</p>