(Added [code]...[/code] tags ~ MOD)

HI,

I have this code that deletes any div that contains class = "comments-box"

$dom = new DOMDocument;
$dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
$xp = new DOMXPath($dom);

// get the node list of div nodes with "target" class
$spanNodeList = $xp->query('//div[contains(@class, "comments-box")]');

foreach ($spanNodeList as $spanNode) {
    $spanNode->parentNode->replaceChild($spanNode->firstChild, $spanNode);
}

I need it to delete all the divs that it also contains
class = "heycomments-box"
class = "sdfcomments-box"
class = "comments-boxsdfdfh"

Regards

    Isn't that what your code does (except, of course, it also discards all of the div's children after the first)?

      Write a Reply...