Jump to content

Recommended Posts

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"

class = "sdgsdgcomments-boxsdfdfh"

Regards

Link to comment
https://forums.phpfreaks.com/topic/309514-remove-a-html-tag-class-dom/
Share on other sites

This time, your answer doesn't help me with anything, sorry

I need that if a div contains a class that includes word "comments-box". example: "23comments-box234"; "sdgcomments-boxsdg" and feels others, is eliminated with DOM code that I wrote above

 

Sorry and Thanks for your time lost with me

I need something like this with Dom

preg_replace('#<div class="(.*?)comments-box(.*?)">(.*?)</div>#', '', $html);  

 

 

Must delete all div, which contains class combinations that contains word comments-box. They can be billions. I can't do it manually

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.