quick fix, regex | July 18th, 2013

include(‘simple_html_dom.php’);
function nestedHTML($node)
{
$doc = $node->ownerDocument;
$frag = $doc->createDocumentFragment();
foreach ($node->childNodes as $child)
{
$frag->appendChild($child->cloneNode(TRUE));
}
return $doc->saveXML($frag);
}
//$html = “<div class=’xyz’><div class=’abc’>contents</div></div>”;  // Add html here
libxml_use_internal_errors(true); // if any warning generate
$doc = new DOMDocument();
$doc->loadHTML($html);
$doc->saveHTML();
$nodes = $doc->getElementsByTagName(‘div’);
foreach ($nodes as $node) {
$class = $node->getAttribute(‘class’);
if($class == ‘entry-content’){   // add class there
echo nestedHTML($node);
}
}

There are no comments yet, add one below.

Leave a Comment


You must be logged in to post a comment.