user3452136
user3452136

Reputation: 125

How to remove class and ID attributes from HTML using Simple HTML Dom Parser

I want to remove all class and ID attributes from HTML by using Simple HTML Dom Parser. I'd like to remove those attributes throughout the entire HTML DOM, regardless of the type of tag. Throughout the HTML doc, there are various tags (li, p, div, etc.) that are being styled based on the CSS selector, and I basically want to remove the styling. Is there a way to traverse the entire DOM without specifying tags to remove all the Class/ID attributes?

Upvotes: 1

Views: 994

Answers (1)

Jared Farrish
Jared Farrish

Reputation: 49208

Seems like it would be something like:

foreach ($html->find('*[id], *[class]') as $element) {
    $element->id = null;
    $element->class = null;
}

https://simplehtmldom.sourceforge.io/manual.htm#section_find https://simplehtmldom.sourceforge.io/manual.htm#section_access

Upvotes: 1

Related Questions