A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearCall to a member function xpath() on a non-object? - page 1
User InfoPosts
Call to a member function xpath() on a non-object?#1
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 xpath() on a non-object.

Below are the lines I'm trying to use to get the image's source tag:

$xpath = '/html/body/div/div/div[5]/div/div/div[2]/div/div[2]/img';          
$html = new DOMDocument();
@$html->loadHTMLFile($target_URL);
$xml = simplexml_import_dom($html);
$source_image = $xml->xpath($xpath);
$source_image = $source_image[0]['src'];


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.

posted date: 2008-12-08 22:49:00


Re: Call to a member function xpath() on a non-object?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-08 22:49:01


Re: Call to a member function xpath() on a non-object?#3
Problem solved. Was funning xpath on an empty string.

posted date: 2008-12-08 23:20:00


Re: Call to a member function xpath() on a non-object?#4
Try this code to first make sure that the document is being parsed correctly.$xpath = '/html/body/div/div/div[5]/div/div/div[2]/div/div[2]/img'; $html = new DOMDocument();@$html->loadHTMLFile($target_URL);$xml = simplexml_import_dom($html); if (!$xml) { echo 'Error while parsing the document'; exit;}$source_image = $xml->xpath($xpath);$source_image = $source_image[0]['src'];

posted date: 2008-12-08 23:24:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.