What function do you use to get innerHTML of a given DOMNode in the PHP DOM implementation? Can someone give reliable, checked solution?
Of course outerHTML will do too.
What function do you use to get innerHTML of a given DOMNode in the PHP DOM implementation? Can someone give reliable, checked solution?
Of course outerHTML will do too.
read in :
http://php.net/manual/en/book.dom.php
<?php
function DOMinnerHTML($element)
{
$innerHTML = "";
$children = $element->childNodes;
foreach ($children as $child)
{
$tmp_dom = new DOMDocument();
$tmp_dom->appendChild($tmp_dom->importNode($child, true));
$innerHTML.=trim($tmp_dom->saveHTML());
}
return $innerHTML;
}
?>
Example:
<?php
$dom= new DOMDocument();
$dom->load($html_string);
$dom->preserveWhiteSpace = false;
$domTable = $dom->getElementsByTagName("table");
foreach ($domTable as $tables)
{
echo DOMinnerHTML($tables);
}
?>