title: Call to a member function xpath() on a non-object?
body: <p>I'm trying to grab an image from a web site using simpleXML and am getting a PHP error saying that I'm trying to call to a member function <code>xpath()</code> on a non-object.</p>
  
  <p>Below are the lines I'm trying to use to get the image's source tag: </p>
  
  <pre><code>$xpath = '/html/body/div/div/div[5]/div/div/div[2]/div/div[2]/img';          
  $html = new DOMDocument();
  @$html-&gt;loadHTMLFile($target_URL);
  $xml = simplexml_import_dom($html);   
  $source_image = $xml-&gt;xpath($xpath);
  $source_image = $source_image[0]['src'];
  </code></pre>
  
  <p>What am I doing wrong? It's pretty clear the second to last line has a problem, but I'm not sure what it is.</p>