3v4l.org

run code in 500+ PHP versions simultaneously
<?php $allowed = array("img", "p","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>'; $doc = new DOMDocument(); $doc->loadHTML($text); $xp = new DOMXPath($doc); $find = '//body//*[not(name() = "'.implode ('" or name() = "', $allowed ). '")]'; echo "XPath = ".$find.PHP_EOL; $toRemove = $xp->evaluate($find); print_r($toRemove); foreach ( $toRemove as $remove ) { $remove->parentNode->removeChild($remove); } // recreate HTML $outHTML = ""; foreach ( $doc->getElementsByTagName("body")[0]->childNodes as $tag ) { $outHTML.= $doc->saveHTML($tag); } echo $outHTML;

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.0130.00621.37
8.5.20.0140.00519.88
8.5.10.0110.00716.92
8.5.00.0150.00820.59
8.4.180.0120.01020.09
8.4.170.0100.01222.22
8.4.160.0160.00622.30
8.4.150.0060.00617.07
8.4.140.0070.01418.09
8.4.130.0120.01018.03
8.4.120.0140.00621.03
8.4.110.0080.01218.84
8.4.100.0160.00618.18
8.4.90.0120.00918.43
8.4.80.0110.00621.71
8.4.70.0070.01319.91
8.4.60.0100.00619.62
8.4.50.0040.00720.77
8.4.40.0100.01018.07
8.4.30.0090.01022.57
8.4.20.0030.01618.95
8.4.10.0110.01120.18
8.3.300.0140.00718.78
8.3.290.0120.01221.16
8.3.280.0150.00718.68
8.3.270.0140.00817.11
8.3.260.0050.01417.03
8.3.250.0040.00419.42
8.3.240.0120.00717.13
8.3.230.0110.00817.04
8.3.220.0050.00317.64
8.3.210.0130.00716.79
8.3.200.0140.00516.85
8.3.190.0040.00417.41
8.3.180.0080.01119.09
8.3.170.0150.00416.85
8.3.160.0070.00317.49
8.3.150.0050.00516.96
8.3.140.0130.00319.46
8.3.130.0080.00018.84
8.3.120.0100.01019.21
8.3.110.0050.00520.94
8.3.100.0030.01324.06
8.3.90.0060.00926.77
8.3.80.0100.00018.93
8.3.70.0130.00616.75
8.3.60.0140.00718.71
8.3.50.0090.00518.81
8.3.40.0070.00718.97
8.3.30.0100.00619.08
8.3.20.0040.00421.26
8.3.10.0000.00823.95
8.3.00.0080.00022.77
8.2.300.0100.01022.58
8.2.290.0120.00920.50
8.2.280.0090.01116.91
8.2.270.0070.01117.43
8.2.260.0110.00718.70
8.2.250.0080.00016.90
8.2.240.0030.00719.35
8.2.230.0070.00322.58
8.2.220.0060.00337.54
8.2.210.0040.00426.77
8.2.200.0060.00316.75
8.2.190.0070.00716.88
8.2.180.0170.01025.92
8.2.170.0060.00919.30
8.2.160.0070.00722.63
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00421.47
8.2.120.0080.00026.35
8.2.110.0000.01021.29
8.2.100.0070.00418.47
8.2.90.0060.00318.13
8.2.80.0040.00418.41
8.2.70.0040.00418.40
8.2.60.0060.00318.59
8.2.50.0030.00618.13
8.2.40.0000.00819.72
8.2.30.0040.00419.54
8.2.20.0040.00418.52
8.2.10.0040.00419.71
8.2.00.0040.00418.52
8.1.340.0110.01019.79
8.1.330.0130.00716.99
8.1.320.0130.00616.53
8.1.310.0070.00716.61
8.1.300.0080.00020.77
8.1.290.0060.00330.84
8.1.280.0110.00425.92
8.1.270.0080.00021.00
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0060.00324.21
8.1.230.0040.01121.38
8.1.220.0050.00318.01
8.1.210.0050.00318.77
8.1.200.0030.00717.63
8.1.190.0000.00817.61
8.1.180.0080.00018.10
8.1.170.0060.00318.92
8.1.160.0000.00719.23
8.1.150.0030.00519.19
8.1.140.0000.00720.55
8.1.130.0030.00320.57
8.1.120.0030.00617.79
8.1.110.0000.00917.70
8.1.100.0080.00017.76
8.1.90.0000.01117.76
8.1.80.0000.00717.76
8.1.70.0030.00317.82
8.1.60.0000.00917.84
8.1.50.0030.00617.88
8.1.40.0000.00817.91
8.1.30.0040.00417.97
8.1.20.0050.00517.99
8.1.10.0030.00617.79
8.1.00.0000.00817.91
8.0.300.0040.00420.15
8.0.290.0050.00317.13
8.0.280.0000.00718.80
8.0.270.0030.00517.65
8.0.260.0000.00620.44
8.0.250.0000.00717.19
8.0.240.0030.00317.34
8.0.230.0030.00617.20
8.0.220.0040.00417.29
8.0.210.0000.00717.13
8.0.200.0030.00717.29
8.0.190.0040.00417.31
8.0.180.0040.00417.26
8.0.170.0060.00317.27
8.0.160.0040.00417.31
8.0.150.0040.00417.21
8.0.140.0050.00217.25
8.0.130.0050.00013.75
8.0.120.0040.00417.15
8.0.110.0040.00417.07
8.0.100.0050.00317.23
8.0.90.0000.00817.04
8.0.80.0130.00817.22
8.0.70.0030.00617.11
8.0.60.0040.00417.15
8.0.50.0070.00317.30
8.0.30.0080.01217.43
8.0.20.0090.00917.09
8.0.10.0040.00417.36
8.0.00.0100.00917.20
7.4.330.0050.00015.55
7.4.320.0030.00316.75
7.4.300.0000.00616.96
7.4.290.0000.00716.92
7.4.280.0030.00616.92
7.4.270.0000.00716.90
7.4.260.0050.00216.77
7.4.250.0070.00016.93
7.4.240.0000.00716.77
7.4.230.0000.00716.75
7.4.220.0000.00817.05
7.4.210.0090.00616.90
7.4.200.0040.00417.02
7.4.160.0080.00816.96
7.4.140.0100.01017.86
7.4.130.0150.00616.76
7.4.120.0060.01216.85
7.4.110.0100.01016.79
7.4.100.0060.01216.84
7.4.90.0060.01116.64
7.4.80.0000.02019.39
7.4.70.0120.01216.80
7.4.60.0040.01416.98
7.4.50.0100.00616.89
7.4.40.0030.01316.86
7.4.00.0030.01315.24
7.3.330.0050.00013.55
7.3.320.0000.00513.55
7.3.310.0000.00716.58
7.3.300.0030.00316.66
7.3.290.0070.00016.68
7.3.280.0080.00916.65
7.3.260.0130.00716.90
7.3.240.0100.00916.83
7.3.230.0110.00616.83
7.3.210.0050.01416.89
7.3.200.0080.00916.64
7.3.190.0030.01316.65
7.3.180.0070.01517.03
7.3.170.0070.01116.66
7.3.160.0090.00616.82
7.3.30.0150.00414.76
7.3.20.1500.01014.88
7.3.10.0510.01515.03
7.3.00.0380.01214.99
7.2.330.0070.01117.01
7.2.320.0030.01517.28
7.2.310.0100.00717.00
7.2.300.0040.01417.08
7.2.290.0060.01116.79
7.2.160.0230.01015.25
7.2.150.0420.01015.09
7.2.140.0480.01315.25
7.2.130.0450.00715.32
7.2.120.0580.01315.37
7.2.110.0680.01015.23
7.2.100.0360.01215.05
7.2.90.0490.00615.22
7.2.80.0340.01215.25
7.2.70.0360.00915.35
7.2.60.0610.00715.20
7.2.50.0850.01315.19
7.2.40.0390.00715.21
7.2.30.0430.00615.44
7.2.20.0490.01015.40
7.2.10.0390.01615.20
7.2.00.0420.00615.10
7.1.270.0590.01014.10
7.1.260.0450.00314.11
7.1.250.0480.00913.96

preferences:
46.43 ms | 1490 KiB | 5 Q