public static function getBody(string $html) : string
{
// If the source code contains <body>, return this element's contents
if (preg_match('~<body([^>]*)>(.*?)</body>~is', $html, $matches)) {
$body = trim($matches[2]);
// Converts <body> inline styles to a newly created <div> element
if (preg_match('~style="[^"]+"~i', $matches[1], $style)) {
$body = '<div ' . $style[0] . '>' . $body . '</div>';
}
return $body;
}
// Return everything otherwise
return $html;
}