http://stackoverflow.com/a/2087136/1998086
10 removals
29 lines
8 additions
28 lines
<?php
<?php
function DOMinnerHTML($element)
function DOMinnerHTML(DOMNode $element)
{
{
$innerHTML = "";
$innerHTML = "";
$children = $element->childNodes;
$children = $element->childNodes;
foreach ($children as $child)
foreach ($children as $child)
{
{
$tmp_dom = new DOMDocument();
$innerHTML .= $element->ownerDocument->saveHTML($child);
$tmp_dom->appendChild($tmp_dom->importNode($child, true));
$innerHTML.=trim($tmp_dom->saveHTML());
}
}
return $innerHTML;
return $innerHTML;
}
}
?>
?>
<?php
<?php
$dom= new DOMDocument();
$dom= new DOMDocument();
$dom->load($html_string);
$dom->preserveWhiteSpace = false;
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->load($html_string);
$domTable = $dom->getElementsByTagName("table");
$domTables = $dom->getElementsByTagName("table");
foreach ($domTable as $tables)
foreach ($domTables as $table)
{
{
echo DOMinnerHTML($tables);
echo DOMinnerHTML($table);
}
}
?>
?>