22 September 2016
How to use a DOM parser and get the contents of the body.
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