3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = " <div id='div-gpt-ad-1456499310532-2' style='height:90px; width:970px;' style=\"height:90px; width:970px;\"> </div>"; // create a new DomDocument object $doc = new DOMDocument(); // load the HTML into the DomDocument object (this would be your source HTML) $doc->loadHTML($input); removeElementsByTagName('style', $doc); // output cleaned html echo $doc->saveHtml(); function removeElementsByTagName($tagName, $document) { $nodeList = $document->getElementsByTagName($tagName); for ($nodeIdx = $nodeList->length; --$nodeIdx >= 0; ) { $node = $nodeList->item($nodeIdx); $node->parentNode->removeChild($node); } }
based on gJe3m
Output for 5.5.0 - 7.3.1
Warning: DOMDocument::loadHTML(): Attribute style redefined in Entity, line: 2 in /in/an1lk on line 11 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><div id="div-gpt-ad-1456499310532-2" style="height:90px; width:970px;"> </div></body></html>