#108 html->find error


When I run the example php script I get an error: Fatal error: Call to a member function find() on a non-object in /mnt/133/sda/0/9/nigelstrang59/htmltry.php on line 6 - it seems to be saying that $html is not an object ....

here is the code (almost a copy paste from sourceforge) - any ideas?
// Pull in PHP Simple HTML DOM Parser
// Get the URL\'s current page content
$html = file_get_html(\'http://www.google.com/\');
$ret = $html->find(\'a\');
echo $ret;



  • Nigel

    Nigel - 2012-07-10

    please note the \ preceding the " are not present in the code

  • nickl-

    nickl- - 2012-09-10

    This fatal error usually appears when trying to use null or something else as an object, iow using the -> to call a method.

    Chances are that for whatever reason file_get_html returned null or false, should verify this. To take simple_html_dom completely out of the equation see if you are able to fetch the url with file_get_contents().

    Please let us know what you find, if you still don't have any luck may I ask that you give a more detailed report including version numbers and step by step process so that someone may reproduce the fault.

    I did your example without the escaped string quotes and it worked.

    You could also try:

    $html = new simple_html_dom();
    $dom = $html->load_file('http://www.google.com/');
    if (!empty($dom))

    Also try something other than google not always the friendliest approach for your first attempts as you are very likely to by confronted by several 3xx responses which you'd need to deal with.

    Good luck!

  • Rahul Sharma

    Rahul Sharma - 2013-09-03

    Hi Nick i am using object oriented method and it is working on my development server. But the problem is that it is not working on live server. Both servers have same configuration.
    I am getting this error on my live server:

    PHP Fatal error: Call to a member function find() on a non-object in tmp_scripts/simple_html_dom.php on line 1113

    I am using following code :
    $html = $html = new simple_html_dom();
    $url = "http://www.hotels.com/hotel/details.html?tab=description&hotelId=".$id."&arrivalDate=08-29-13&departureDate=08-30-13&rooms[0].numberOfAdults=1&roomno=1&validate=false&previousDateful=false&reviewOrder=date_newest_first#reviews";
    $count = count($html->find('div.review'));
    if($count > 0){
    foreach($html->find('div.review') as $data ){
    $id can contain 243147,141744
    on dev server when I am using 243147.. it is retrieving the 0 count (as it should) and getting data for second values.
    but on live server I am getting fatal error.

    I also tried ur code (that is getting load_file in variable and then accessing other methods using that). In that case I am not getting error. but also not getting any data.


    Last edit: Rahul Sharma 2013-09-03
  • Naved Ahmed

    Naved Ahmed - 2014-04-05

    Thanks rahul... thanx a lot 4 ur answer... :D

    Last edit: Naved Ahmed 2014-04-05
  • John Schlick

    John Schlick - 2014-04-05

    $ret = $html->find('a');

    returns an ARRAY of all of the dom objects that represent an a tag.

    echo doesn't like arrays.

    $ret = $html->find('a', 0);
    to only return the FIRST a tag in the document.
    but then... it will be an object, and echo probably won't like that either.

    so maybe var_dump or print_r instead of echo?


Log in to post a comment.