I have this html code:
<html>
<head>
...
</head>
<body>
<div>
<div class="foo" data-type="bar">
SOMECONTENTWITHMORETAGS
</div>
</div>
</body>
I already can get the "foo" element (but only its content) with this function:
private function get_html_from_node($node){
$html = '';
$children = $node->childNodes;
foreach ($children as $child) {
$tmp_doc = new DOMDocument();
$tmp_doc->appendChild($tmp_doc->importNode($child,true));
$html .= $tmp_doc->saveHTML();
}
return $html;
}
But I'd like to return all html tags (including its attributes) of DOMElement. How I can do that?
html_from_node
class="foo"
you are doing it not correct. There is much easy and short way of doing this. – Pilotage