0

I am trying to extract the content of a <div> nested inside a <code> tag with PHP Simple HTML DOM Parser but I am always getting the error Trying to get property of non-object in... as if the parser was finding nothing inside my <div>

The code I'm using is

include_once('simplehtmldom_1_5/simple_html_dom.php');

// Create a DOM object
$html = new simple_html_dom();

// Load HTML
$html->load('<code><div>hello</div></code>');

// Extract div content
echo $html->find('div',0)->innertext;

But if instead of using <code><div>hello</div></code> as my sample code i use <span><div>hello</div></span> it works... it seems like I'm having problems only looking inside the code tag.

What's wrong with what i'm doing? Hope you guys can point me in the right direction, thank you very much for your support!

2 Answers 2

1

simplehtmldom among others strips out pre formatted tags. If you want code tag to be recognized delete or comment out line 1076 in *simple_html_dom.php*

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

1 Comment

i commented the line 1060 which removed the <code> tag and everything worked, thanks!
0

According to the source code for Simple HTML DOM it automagically removes code tags when it loads the HTML into the parser.

If you need the functionality you'll need to remove the reference to remove_noise() in the load() function within simplehtmldom.php.

This should produce the results you expect, but obviously may well introduce other issues, depending on the authors reasoning for removing the tags in the first place.

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.