title: PHP - Iterate over google results
body: <p>I have a simple CURL script that searches Google for "Batman", then saves the result in a file...</p>
  
  <p>Can someone tell me a good way of iterating through the file to find each of the search results title and URL, please?</p>
  
  <p>This is my code:</p>
  
  <pre><code>function get_remote_file_to_cache()
  {
      $the_site = "https://www.google.se/webhp?sourceid=chrome-instant&amp;rlz=1C5CHFA_enSE555SE556&amp;ion=1&amp;espv=2&amp;ie=UTF-8#newwindow=1&amp;q=batman";
  
  
      $curl = curl_init ();
      $fp = fopen ( "temp_file.txt", "w" );
      curl_setopt ( $curl, CURLOPT_URL, $the_site );
      curl_setopt ( $curl, CURLOPT_FILE, $fp );
  
      curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, TRUE );
  
      curl_exec ( $curl );
  
      $httpCode = curl_getinfo ( $curl, CURLINFO_HTTP_CODE );
      if ($httpCode == 404)
      {
          touch ( 'cache/404_err.txt' );
      } /*
      * else { touch('cache/'.rand(0, 99999).'--all_good.txt'); }
      */
      else
      {
          $contents = curl_exec ( $curl );
          fwrite ( $fp, $contents );
      }
  
      curl_close ( $curl );
      fclose ( $fp );
  }
  
  echo rand(1, 425).get_remote_file_to_cache();
  </code></pre>