Mark Segal
Mark Segal

Reputation: 5550

How to parse HTML correctly with DOMDocument?


Lets say I have this type of HTML website:

stuff
<div id="123">
*HTML CODE I NEED*
</div>
stuff
<div id="234">
*HTML CODE I NEED*
</div>
more stuff

How can I extract HTML CODE I NEED from those div's, given that I know their IDs ?
Thank you!

Upvotes: 0

Views: 108

Answers (1)

Felix Kling
Felix Kling

Reputation: 816252

You can get the nodes with DOMDocument::getElementById [docs] and the text content with the textContent [docs] property.

If you want the inner HTML of the nodes, you can call DOMDocument::saveHTML [docs].

Upvotes: 1

Related Questions