1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 function stripStyleTags($html='') { $dom = new DOMDocument; $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); $xpath = new DOMXPath($dom); // Find any element with the style attribute $nodes = $xpath->query('//*[@style]'); // Loop the elements foreach ($nodes as $node) { // Remove style attribute $node->removeAttribute('style'); } $html = $dom->saveHTML(); return $html; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter