3v4l.org

run code in 500+ PHP versions simultaneously
<?php $allowed_tags = array("img", "p"); $allowed_attributes = array("style"); $text='<img src="image.gif" onerror="myFunction()" style="background:red" onclick="myFunction()"> <p>A function is triggered if an error occurs when loading the image. The function shows an alert box with a text. In this example we refer to an image that does not exist, therefore the onerror event occurs.</p> <div>a sample div with a <span>span in it</span></div> <p>a sample para with a <span>span in it</span></p> <script> function myFunction() { alert(\'The image could not be loaded.\'); } </script>'; function remove_nodes_and_attributes($doc, $node, $allowed_tags, $allowed_attributes) { $xpath = new DOMXPath($doc); foreach ($xpath->query('./*', $node) as $child) { if (!in_array($child->nodeName, $allowed_tags)) { $node->removeChild($child); continue; } $a = 0; while ($a < $child->attributes->length) { $attribute = $child->attributes->item($a)->name; if (!in_array($attribute, $allowed_attributes)) { $child->removeAttribute($attribute); // don't increment the pointer as the list will shift with the removal of the attribute } else { // allowed attribute, skip it $a++; } } // remove any children as necessary remove_nodes_and_attributes($doc, $child, $allowed_tags, $allowed_attributes); } } $doc = new DOMDocument(); $doc->loadHTML("<html>$text</html>", LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $html = $doc->getElementsByTagName('html')[0]; remove_nodes_and_attributes($doc, $html, $allowed_tags, $allowed_attributes); echo substr($doc->saveHTML(), 6, -8);

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.5.30.0080.00921.70
8.5.20.0140.00819.63
8.5.10.0090.00917.10
8.5.00.0130.01020.49
8.4.180.0160.00622.38
8.4.170.0110.01224.30
8.4.160.0150.01023.47
8.4.150.0070.00617.13
8.4.140.0130.01118.10
8.4.130.0110.00918.39
8.4.120.0110.00624.71
8.4.110.0130.00721.14
8.4.100.0110.01019.06
8.4.90.0030.00621.13
8.4.80.0120.00819.12
8.4.70.0070.00918.08
8.4.60.0110.00920.92
8.4.50.0110.01019.13
8.4.40.0070.01318.36
8.4.30.0070.01422.94
8.4.20.0100.01018.99
8.4.10.0150.00619.86
8.3.300.0130.00719.76
8.3.290.0100.01122.97
8.3.280.0100.01318.80
8.3.270.0110.00917.00
8.3.260.0050.00416.99
8.3.250.0070.01219.21
8.3.240.0120.00717.55
8.3.230.0040.00417.09
8.3.220.0090.01019.16
8.3.210.0080.00518.73
8.3.200.0130.00717.09
8.3.190.0070.01019.35
8.3.180.0070.01118.82
8.3.170.0150.00319.13
8.3.160.0000.00819.42
8.3.150.0120.00818.76
8.3.140.0040.00417.79
8.3.130.0080.00018.64
8.3.120.0130.00619.04
8.3.110.0060.00316.98
8.3.100.0060.00317.00
8.3.90.0100.01018.72
8.3.80.0090.00417.97
8.3.70.0100.00716.75
8.3.60.0140.00718.55
8.3.50.0090.00418.59
8.3.40.0120.00619.29
8.3.30.0040.01219.27
8.3.20.0040.00421.15
8.3.10.0080.00023.86
8.3.00.0040.00422.84
8.2.300.0090.01118.47
8.2.290.0100.01020.93
8.2.280.0080.01122.45
8.2.270.0120.00619.30
8.2.260.0040.00418.70
8.2.250.0080.00018.83
8.2.240.0050.00317.01
8.2.230.0090.00020.94
8.2.220.0060.00324.06
8.2.210.0000.00826.77
8.2.200.0090.00018.66
8.2.190.0140.00416.75
8.2.180.0140.00418.79
8.2.170.0070.01422.96
8.2.160.0070.00722.58
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0000.00821.28
8.2.110.0060.01322.75
8.2.100.0090.00318.28
8.2.90.0000.00818.53
8.2.80.0040.00417.99
8.2.70.0040.00418.16
8.2.60.0060.00318.41
8.2.50.0000.00818.10
8.2.40.0050.00219.67
8.2.30.0040.00419.63
8.2.20.0040.00418.62
8.2.10.0020.00519.73
8.2.00.0040.00418.52
8.1.340.0090.01117.88
8.1.330.0090.01122.62
8.1.320.0100.00916.37
8.1.310.0100.00319.05
8.1.300.0160.00318.36
8.1.290.0030.01018.88
8.1.280.0070.00725.92
8.1.270.0090.00021.05
8.1.260.0000.00826.35
8.1.250.0000.00828.09
8.1.240.0070.01024.11
8.1.230.0000.01121.30
8.1.220.0030.00518.29
8.1.210.0000.00919.41
8.1.200.0050.00317.73
8.1.190.0030.00517.61
8.1.180.0040.00418.10
8.1.170.0040.00419.08
8.1.160.0000.00819.31
8.1.150.0000.00819.38
8.1.140.0070.00020.68
8.1.130.0000.00817.80
8.1.120.0070.00317.80
8.1.110.0000.00817.88
8.1.100.0080.00017.78
8.1.90.0040.00417.78
8.1.80.0000.00817.77
8.1.70.0040.00417.78
8.1.60.0040.00417.92
8.1.50.0060.00317.92
8.1.40.0000.00917.94
8.1.30.0040.00418.08
8.1.20.0090.00017.91
8.1.10.0040.00417.94
8.1.00.0000.00817.94
8.0.300.0040.00420.54
8.0.290.0120.00017.25
8.0.280.0030.00318.84
8.0.270.0030.00517.64
8.0.260.0050.00217.16
8.0.250.0030.00317.27
8.0.240.0070.00017.40
8.0.230.0000.00817.35
8.0.220.0030.00517.34
8.0.210.0000.00817.32
8.0.200.0030.00317.24
8.0.190.0050.00217.33
8.0.180.0080.00017.33
8.0.170.0040.00417.35
8.0.160.0040.00417.20
8.0.150.0030.00517.19
8.0.140.0080.00417.11
8.0.130.0080.00013.70
8.0.120.0040.00417.22
8.0.110.0050.00217.16
8.0.100.0000.00817.00
8.0.90.0040.00417.26
8.0.80.0060.01117.39
8.0.70.0000.00817.12
8.0.60.0050.00217.36
8.0.50.0000.00817.25
8.0.30.0080.01217.44
8.0.20.0130.01017.47
8.0.10.0040.00417.21
8.0.00.0140.00717.19
7.4.330.0020.00215.55
7.4.320.0070.00016.94
7.4.300.0050.00316.99
7.4.290.0000.00716.93
7.4.280.0040.00416.86
7.4.270.0000.01017.00
7.4.260.0050.00317.06
7.4.250.0030.00416.90
7.4.240.0040.00416.91
7.4.230.0030.00317.08
7.4.220.0040.00416.89
7.4.210.0080.01016.90
7.4.200.0070.00017.02
7.4.160.0100.00617.03
7.4.140.0120.00617.86
7.4.130.0120.00616.94
7.4.120.0090.00917.00
7.4.110.0110.00716.96
7.4.100.0100.01316.89
7.4.90.0100.00716.67
7.4.80.0110.00719.39
7.4.70.0140.00317.11
7.4.60.0100.01016.88
7.4.50.0130.00316.67
7.4.40.0130.00317.02
7.4.00.0080.01015.20
7.3.330.0000.00513.70
7.3.320.0030.00313.67
7.3.310.0000.00716.84
7.3.300.0030.00316.75
7.3.290.0000.00716.68
7.3.280.0090.00816.76
7.3.260.0110.00916.85
7.3.240.0080.01216.83
7.3.230.0060.01316.89
7.3.210.0150.00417.09
7.3.200.0050.01317.11
7.3.190.0030.01316.78
7.3.180.0100.00716.66
7.3.170.0180.00017.00
7.3.160.0030.01316.75
7.3.120.0070.00715.00
7.3.110.0130.00615.16
7.3.100.0120.00314.65
7.3.90.0070.00714.77
7.3.80.0090.00615.02
7.3.70.0030.01315.11
7.3.60.0120.00314.93
7.3.50.0060.00614.92
7.3.40.0060.00915.09
7.3.30.0090.00914.98
7.3.20.0700.00815.93
7.3.10.0820.00715.92
7.3.00.0590.00915.84
7.2.330.0110.00916.79
7.2.320.0120.01716.88
7.2.310.0070.01017.14
7.2.300.0090.00817.25
7.2.290.0060.01117.04
7.2.250.0030.01315.43
7.2.240.0040.01815.18
7.2.230.0040.01215.13
7.2.220.0070.00715.47
7.2.210.0060.00615.13
7.2.200.0070.01015.13
7.2.190.0030.00615.29
7.2.180.0060.01015.14
7.2.170.0050.00515.38
7.2.160.0030.01215.12
7.2.150.1810.00615.29
7.2.140.0920.00315.18
7.2.130.1490.00315.32
7.2.120.1360.01015.21
7.2.110.1430.01015.22
7.2.100.1630.00715.25
7.2.90.1970.01015.44
7.2.80.1910.00315.30
7.2.70.1490.01315.06
7.2.60.2040.00715.11
7.2.50.1710.01015.11
7.2.40.1520.01015.14
7.2.30.1260.01015.28
7.2.20.1430.01015.20
7.2.10.1210.01415.20
7.2.00.0930.00315.25
7.1.330.0070.00716.18
7.1.320.0100.00716.18
7.1.310.0110.00315.96
7.1.300.0000.00916.04
7.1.290.0070.00715.96
7.1.280.0070.00716.02
7.1.270.0990.00615.18
7.1.260.0660.00515.09
7.1.250.1540.00313.96

preferences:
46.48 ms | 1551 KiB | 5 Q