Archive for the ‘regex’ Category

quick fix, regex | No Comments | 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);
}
}