3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripTagFormatting(DOMText $textNode) { $css = []; $existingStyles = ''; $currentNode = $textNode->parentNode; do { switch (strtolower($currentNode->tagName)) { case 'font': if ($currentNode->hasAttribute('color') && !isset($css['color'])) { $css['color'] = $currentNode->getAttribute('color'); } if ($currentNode->hasAttribute('size') && !isset($css['font-size'])) { $css['font-size'] = $currentNode->getAttribute('size') . 'px'; } if ($currentNode->hasAttribute('face') && !isset($css['font-family'])) { $css['font-family'] = $currentNode->getAttribute('face'); } break; case 'b': if (!isset($css['font-weight'])) { $css['font-weight'] = 'bold'; } break; case 'i': if (!isset($css['font-style'])) { $css['font-style'] = 'italic'; } break; default: if ($currentNode->hasAttribute('style')) { $existingStyles = $currentNode->getAttribute('style'); } break 2; } } while($currentNode->parentNode->childNodes->length == 1 && $currentNode = $currentNode->parentNode); var_dump($currentNode->tagName, $css); } $html = '<FONT FACE="League" SIZE="15" COLOR="#000000"><font COLOR="#ff00ff" SIZE="18"><b><font SIZE="23"><font SIZE="27"><font SIZE="23"><font SIZE="18"><font SIZE="23">Moet Flip make-up dragen? <br />Stem mee in de poll!!</font></font></font></font></font></b></font><br /></FONT>'; $dom = new DOMDOcument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $nodes = $xpath->evaluate("/html/body//text()"); foreach ($nodes as $node) { stripTagFormatting($node); } var_dump($dom->saveHTML());
Output for git.master, git.master_jit, rfc.property-hooks
string(4) "font" array(3) { ["font-size"]=> string(4) "23px" ["font-weight"]=> string(4) "bold" ["color"]=> string(7) "#ff00ff" } string(4) "font" array(3) { ["font-size"]=> string(4) "23px" ["font-weight"]=> string(4) "bold" ["color"]=> string(7) "#ff00ff" } string(404) "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><font face="League" size="15" color="#000000"><font color="#ff00ff" size="18"><b><font size="23"><font size="27"><font size="23"><font size="18"><font size="23">Moet Flip make-up dragen? <br>Stem mee in de poll!!</font></font></font></font></font></b></font><br></font></body></html> "

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.46 ms | 403 KiB | 8 Q