To use a DOMDocument and get the contents of the body in PHP, you can use the DOMDocument class, which provides a way to parse and manipulate XML and HTML documents. Here is an example of how to use DOMDocument to parse an HTML document and get the contents of the body tag.
Source code viewer
<?php // HTML to Dom Document. $doc = new DOMDocument(); $doc->strictErrorChecking = false; $doc->loadHTML('<?xml encoding="UTF-8" ?>' . $content); // Get body tag. $body = $doc->getElementsByTagName('body'); if ($body and $body->length > 0) { $body = $body->item(0); // Do stuff with the body tag... // Get altered HTML and clean up. $html = $doc->saveHTML(); // Return modified HTML. echo $html; }Programming Language: PHP