title: Recursively search all directories for an array of strings in php
body: <p>I am new to PHP coding and here am looking for fastest way to do recursive search on all directories for an array of strings.</p>
  
  <p>I am doing this way</p>
  
  <pre><code>$contents_list = array("xyz","abc","hello"); // this list can grow any size
  $path = "/tmp/"; //user will give any path which can contain multi level sub directories
  
  $dir = new RecursiveDirectoryIterator($path);
  
  foreach(new RecursiveIteratorIterator($dir) as $filename =&gt; $file) {
      $fd = fopen($file,'r');
      if($fd) {
          while(!feof($fd)) {
              $line = fgets($fd);
              foreach($contents_list as $content) {
                  if(strpos($line, $content) != false) {
                      echo $line."\n";
                  }
              }         
          }
      }
      fclose($fd);
  }
  </code></pre>
  
  <p>Here I am recursively iterating over all directories and then again on each file iterate over contents array to search. </p>
  
  <p>Is there any better way to do kind of search ? Please suggest for faster alternative.</p>
  
  <p>Thanks</p>