title: searching a string in pdf file through php
body: <p>I am trying to search a string in pdf file through PHP code. I have made php code to search string in TEXT file, this code takes desire search string, and match this string to the content of TEXT file, and return the complete line where the string matches with the content of text file. </p>
  
  <p>This similar kind of work I want to do with PDF file, but not getting any clue, i searched a class class.pdf2text.php, but this class returns entire content of the pdf file in text format. </p>
  
  <p>I need some guidance and suggestion, to complete this task.  </p>
  
  <p>here is my code</p>
  
  <pre><code>include('class.pdf2text.php');
  
  $a = new PDF2Text();
  
  $a-&gt;setFilename('file.pdf'); 
  
  $a-&gt;decodePDF();
  
   $data = $a-&gt;output();// stored the whole text into a variable
  
  $myfile = "file.txt";
  
  $fh = fopen($myfile, 'w');
  
  fwrite($fh, $data);// write all the text into a text file
  
  $file = 'file.txt';
  
  $searchfor = 'string to search';
  
  header('Content-Type: text/plain');
  
  $result = getLineWithString($file, $searchfor);// search test string in text file
  
  function getLineWithString($file, $searchfor) {
  
      $lines = file($file);
  
      foreach ($lines as $line) {
  
          if (strpos($line, $searchfor) !== false) {
  
              return $line;enter code here
  
          }
  
      }
  
      return -1;
  
  }
  
  echo $result;
  </code></pre>