3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getColor($domnode) { while($domnode->parentNode) { if ($domnode->parentNode->getAttribute('color')) { return $domnode->parentNode->getAttribute('color'); } } } $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) { $color = getColor($node); var_dump($color); if ($color) { $span = $document->createElement('span'); $span->setAttribute('style', 'color: ' . $color . ';'); var_dump($node); $node->parentNode->replaceChild($span, $node); } } var_dump($dom->saveHTML());
Output for 5.3.7 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0

Process exited with code 137.