0
$html = file_get_html($response);
$displaybody = $html->find('div[id="item"]');
echo $displaybody->plaintext

I'm using html dom parser to and using find() funtion but i got an error like this :

PHP Fatal error: Uncaught Error: Call to a member function find() on boolean

can someone tell me why ?

4
  • i'm guessing because the dom tag is not found. Commented Mar 9, 2017 at 18:48
  • do an if(find('div[id="item"]')) print true else print false. True, means dom tag exists, false means it doesn't ('item') can't be found Commented Mar 9, 2017 at 18:52
  • I'd suggest you output $html to debug log or console and manually see if the div id item is in fact there. $100USD says it's not there, null or blank. Commented Mar 9, 2017 at 18:55
  • Simple HTML Dom can react adversely in some cases as well; it's better if you use PHP's built in DOMDocument, and DOMXPath php.net/Domxpath Commented Mar 9, 2017 at 18:57

2 Answers 2

1

Try this answer which actually worked for me.

The reason for this error is: the simple HTML DOM does not return the object if the size of the response from url is greater than 600000. You can void it by changing the simple_html_dom.php file. Remove strlen($contents) > MAX_FILE_SIZE from the if condition of the file_get_html function. This will solve your issue.

This is the link https://stackoverflow.com/a/26773587/2513964

Sign up to request clarification or add additional context in comments.

1 Comment

Or just update the MAX_FILE_SIZE defined in that same file.
0

PHP Fatal error: Uncaught Error: Call to a member function find() on boolean

This generally means that find('div[id="item"]') is false or not found.

I'd suggest you output $html to console or log and verify that div id "item" is in fact in there.

Also use DOMDocument library and use getElementById

public DOMElement DOMDocument::getElementById ( string $elementId )

Should grab the first instance of 'item' (assuming if there's more than one you want the first one)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.