Lets assume my $html looks like this:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">document.createElement("video");document.createElement("audio");document.createElement("track");</script>
<script type="text/javascript" src="/gui/default/tinymcecontent.js"></script>
<script type="text/javascript" src="/includes/js/video-js/video.min.js"></script>
<link rel="stylesheet" href="/includes/js/video-js/video-js.css" />
<script type="text/javascript">document.createElement("video");document.createElement("audio");document.createElement("track");</script>
<script type"text/javascript" src="/includes/js/video-js/video.js"></script/>
<link rel="stylesheet" href="/includes/js/video-js/video-js.css" />
</head>
<body style="font-family: arial;font-size: 12px;">
<p> </p>
<table width="100%">
</table>
</body>
</html>
When I try to parse only elements, that are inside body tag with commands:
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
libxml_use_internal_errors(false);
$full_dom = $dom->getElementsByTagName('body')->item(0);
The result of
$dom->saveHTML($full_dom)
is
<body>
<p>\/><link rel=\"stylesheet\" href=\"\/includes\/js\/video-js\/video-js.css\"><\/p>
<p>\u00a0<\/p>
<table width=\"100%\"><\/table>
<\/body>
Element
<p>\/><link rel=\"stylesheet\" href=\"\/includes\/js\/video-js\/video-js.css\"><\/p>
comes from where? Everything else is good, just this element gets transfered from head tag into elements of body tag..