I want to get entire body tag content using DOM Document.
I used following code:
$dom = new domDocument;
/*** load the html into the object ***/
$dom->loadHTML($html);
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('body')->item(0)->nodeValue;
This gives me TExt. I want entire body content.
The built-in DOM parser makes it possible to process XML documents in PHP.
The DOMDocument::getElementsByTagName() function is an inbuilt function in PHP which is used to return a new instance of class DOMNodeList which contains all the elements of local tag name.
DOMDocument::loadHTMLThe function parses the HTML contained in the string source . Unlike loading XML, HTML does not have to be well-formed to load. This function may also be called statically to load and create a DOMDocument object.
$dom = new domDocument;
$dom->loadHTML($html);
// ... change, replace ...
// ... mock, traverse ..
$body = $dom->documentElement->lastChild;
$dom->saveHTML($body);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With