3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isHTMLTextNode(DOMNode $node) { return $node instanceof DOMText || ($node instanceof DOMElement && strtolower($node->tagName) === 'br'); } function hasMultipleNonTextChildren(DOMElement $element) { $foundOne = false; foreach ($element->childNodes as $child) { if (!isHTMLTextNode($child)) { if ($foundOne) { return true; } $foundOne = true; } } return false; } function setStylesOnElement(DOMElement $element, array $css) { $styles = ltrim(rtrim($element->getAttribute('style'), ';') . '; ', ';'); foreach ($css as $prop => $val) { $styles .= $prop . ': ' . $val . '; '; } $element->setAttribute('style', trim($styles)); } function getCSSEquivs(DOMElement $element) { switch (strtolower($element->tagName)) { case 'font': $css = []; if ($element->hasAttribute('color')) { $css['color'] = $element->getAttribute('color'); } if ($element->hasAttribute('size')) { $css['font-size'] = $element->getAttribute('size') . 'px'; } if ($element->hasAttribute('face')) { $css['font-family'] = $element->getAttribute('face'); } return $css; case 'b': return ['font-weight' => 'bold']; case 'i': return ['font-style' => 'italic']; } return null; } function pullChildrenUp(DOMElement $element) { $children = []; $current = $element->firstChild; do { $next = $current->nextSibling; $children[] = $element->removeChild($current); } while ($current = $next); $parent = $element->parentNode; $before = $element->nextSibling; $parent->replaceChild(array_shift($children), $element); while ($children) { $parent->insertBefore(array_shift($children), $before); } } function pullChildrenDownIntoSpan($element, array $css = []) { $span = $element->ownerDocument->createElement('span'); $span->appendChild($element->replaceChild($span, $element->firstChild)); while ($span->nextSibling) { $span->appendChild($element->removeChild($span->nextSibling)); } return $span; } function stripFormattingTags(DOMText $textNode) { $css = []; $currentNode = $textNode->parentNode; while ($currentNode && !hasMultipleNonTextChildren($currentNode)) { if (null === $equivs = getCSSEquivs($currentNode)) { break; } $css = array_merge($equivs, $css); $parentNode = $currentNode->parentNode; pullChildrenUp($currentNode); $currentNode = $parentNode; } if ($currentNode->tagName !== 'span') { $currentNode = pullChildrenDownIntoSpan($currentNode); } if ($css) { setStylesOnElement($currentNode, $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) { stripFormattingTags($node); } var_dump($dom->saveHTML());

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0110.00716.75
8.3.50.0120.01222.16
8.3.40.0070.00719.29
8.3.30.0070.00719.51
8.3.20.0040.00420.77
8.3.10.0050.00323.89
8.3.00.0000.00821.32
8.2.180.0170.00718.66
8.2.170.0120.00622.96
8.2.160.0030.01422.59
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0080.00020.45
8.2.110.0070.00322.63
8.2.100.0110.00020.85
8.2.90.0040.00419.72
8.2.80.0050.00317.97
8.2.70.0030.00718.00
8.2.60.0000.01118.41
8.2.50.0030.00518.07
8.2.40.0040.00420.38
8.2.30.0000.00818.69
8.2.20.0000.00818.14
8.2.10.0000.00818.46
8.2.00.0000.00918.12
8.1.280.0100.00725.92
8.1.270.0080.00024.20
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00321.34
8.1.230.0040.00819.54
8.1.220.0040.00418.16
8.1.210.0030.00518.77
8.1.200.0070.00717.73
8.1.190.0040.00417.63
8.1.180.0000.00818.10
8.1.170.0060.00319.01
8.1.160.0000.00822.36
8.1.150.0000.00919.02
8.1.140.0060.00317.82
8.1.130.0000.00918.20
8.1.120.0040.00417.80
8.1.110.0040.00417.88
8.1.100.0040.00417.92
8.1.90.0020.00517.79
8.1.80.0040.00417.78
8.1.70.0040.00417.86
8.1.60.0060.00317.91
8.1.50.0040.00417.97
8.1.40.0000.00817.93
8.1.30.0050.00318.01
8.1.20.0050.00318.11
8.1.10.0040.00418.02
8.1.00.0050.00317.83
8.0.300.0040.00418.77
8.0.290.0040.00417.25
8.0.280.0040.00418.87
8.0.270.0030.00517.61
8.0.260.0070.00017.63
8.0.250.0040.00417.43
8.0.240.0110.00017.42
8.0.230.0040.00417.35
8.0.220.0040.00417.36
8.0.210.0000.00717.33
8.0.200.0040.00717.35
8.0.190.0050.00217.32
8.0.180.0020.00517.27
8.0.170.0030.00517.20
8.0.160.0040.00417.24
8.0.150.0040.00417.33
8.0.140.0060.00317.27
8.0.130.0000.00613.75
8.0.120.0050.00517.17
8.0.110.0030.00517.41
8.0.100.0050.00317.36
8.0.90.0030.00617.43
8.0.80.0100.00617.35
8.0.70.0030.00617.16
8.0.60.0000.00817.13
8.0.50.0060.00317.29
8.0.30.0090.01017.53
8.0.20.0100.01117.44
8.0.10.0040.00417.43
8.0.00.0090.01017.21
7.4.330.0050.00015.00
7.4.320.0050.00316.88
7.4.300.0000.00716.81
7.4.290.0030.00516.88
7.4.280.0000.00817.04
7.4.270.0080.00017.05
7.4.260.0030.00416.96
7.4.250.0040.00416.94
7.4.240.0020.00616.93
7.4.230.0030.00617.08
7.4.220.0040.01516.79
7.4.210.0090.00616.93
7.4.200.0040.00416.84
7.4.160.0090.00616.85
7.4.150.0070.01317.40
7.4.140.0180.00317.86
7.4.130.0120.00616.79
7.4.120.0090.00916.71
7.4.110.0120.00616.85
7.4.100.0160.00616.75
7.4.90.0150.00917.06
7.4.80.0070.01319.39
7.4.70.0110.00616.78
7.4.60.0070.01517.00
7.4.50.0060.00317.11
7.4.40.0120.00616.80
7.4.30.0030.01516.87
7.4.00.0040.01415.12
7.3.330.0000.00613.66
7.3.320.0030.00413.67
7.3.310.0040.00416.82
7.3.300.0040.00416.73
7.3.290.0000.01516.74
7.3.280.0060.01216.75
7.3.270.0110.00717.40
7.3.260.0050.01416.96
7.3.250.0110.00816.79
7.3.240.0070.01416.90
7.3.230.0150.00316.88
7.3.210.0100.01916.88
7.3.200.0130.00319.39
7.3.190.0110.01116.71
7.3.180.0120.00317.05
7.3.170.0150.00316.79
7.3.160.0160.00016.79
7.3.120.0070.01114.98
7.2.330.0090.00917.20
7.2.320.0110.01117.17
7.2.310.0060.01316.91
7.2.300.0100.00917.31
7.2.290.0030.01317.30
7.2.00.0000.01319.51
7.1.100.0040.00818.17
7.1.70.0000.00917.47
7.1.60.0130.00017.35
7.1.50.0190.01634.86
7.1.00.0000.08022.63
7.0.200.0000.00916.95
7.0.140.0030.07322.17
7.0.60.0130.07720.21
7.0.50.0100.07318.09
7.0.40.0200.07320.46
7.0.30.0630.06320.56
7.0.20.0270.08020.30
7.0.10.0230.06320.38
7.0.00.0070.09020.45
5.6.280.0100.07021.05
5.6.210.0130.07320.64
5.6.200.0100.05018.41
5.6.190.0070.07320.75
5.6.180.0070.08320.71
5.6.170.0300.06020.91
5.6.160.0130.07320.68
5.6.150.0070.03718.42
5.6.140.0070.04318.39
5.6.130.0070.08318.41
5.6.120.0030.05721.25
5.6.110.0100.08721.13
5.6.100.0170.07721.19
5.6.90.0030.04021.18
5.6.80.0070.08720.57
5.6.70.4400.04020.58
5.5.350.0170.07020.52
5.5.340.0000.04318.17
5.5.330.0000.06320.46
5.5.320.0200.04320.42
5.5.310.0300.07320.45
5.5.300.0030.05718.21
5.5.290.0070.08018.16
5.5.280.0100.08021.11
5.5.270.0100.04721.09
5.5.260.0130.06721.05
5.5.250.0030.09320.79
5.5.240.0070.06720.34
5.4.450.1970.04719.79
5.4.440.2030.04319.64
5.4.430.1900.02719.42
5.4.420.0830.04019.42
5.4.410.0000.04019.25
5.4.400.0070.08319.16
5.4.390.1630.04319.39
5.4.380.1730.04019.38
5.4.370.2000.04719.46
5.4.360.1930.04019.06
5.4.350.1900.04319.46
5.4.340.2030.04319.21
5.4.320.2000.04719.28
5.4.310.2030.04319.21
5.4.300.1800.03719.30
5.4.290.1800.03319.21
5.4.280.1570.05019.31
5.4.270.1830.03019.10
5.4.260.2100.04319.22
5.4.250.2030.04019.17
5.4.240.1930.03719.09
5.4.230.1930.04719.29
5.4.220.2030.03019.20
5.4.210.2030.03319.21
5.4.200.1870.03319.29
5.4.190.2030.04319.25
5.4.180.1800.03319.20
5.4.170.1470.04319.19
5.4.160.0070.06719.19
5.4.150.0000.04319.21
5.4.140.1530.02316.88
5.4.130.1800.04016.59
5.4.120.1830.03316.60
5.4.110.1870.03316.76
5.4.100.1830.03716.75
5.4.90.1970.04316.77
5.4.80.1970.03716.44
5.4.70.1870.03716.77
5.4.60.1870.03716.73
5.4.50.1970.03016.73
5.4.40.1800.03716.40
5.4.30.1900.03016.75
5.4.20.1900.03016.73
5.4.10.2370.03316.43
5.4.00.1970.02316.32
5.3.290.2000.04014.60
5.3.280.1970.03314.58
5.3.270.2100.04714.54
5.3.260.2100.03714.53
5.3.250.2130.04014.62
5.3.240.1700.04314.59
5.3.230.1930.04314.72
5.3.220.0670.04314.59
5.3.210.0000.04314.50
5.3.200.0000.04314.66
5.3.190.1830.04014.66
5.3.180.2070.03314.80
5.3.170.2000.04014.57
5.3.160.1800.04014.61
5.3.150.1870.02714.49
5.3.140.2030.03714.65
5.3.130.2000.04314.57
5.3.120.2030.05314.65
5.3.110.2200.04314.64
5.3.100.2070.04014.11
5.3.90.0970.04313.95
5.3.80.0070.06714.03
5.3.70.0070.03314.20

preferences:
41.4 ms | 401 KiB | 5 Q