DOMElement Content Example
So if I had a HTML document already loaded into a variable $html, and I wanted to extract the value of an element with the ID of “example”, I could do something like this.
$doc = new DOMDocument() $doc->loadHTML($html); $element = $doc->getElementById('example'); echo $element->nodeValue;
A DOMNode also has a textContent property that can be used. This will return all the text for the node and descendants, which may not always be what you are hoping for.