3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @link http://stackoverflow.com/questions/26293581/how-to-select-2nd-element-with-same-tag-using-dom-xpath/26324381#26324381 */ $buffer = <<<BUFFER <div class="fly"> <img src="a.png" class="badge"> <img class="aye" data-original="b.png" width="130" height="253" /> <div class="to"> <h4>Fly To The Moon</h4> <div class="clearfix"> <div class="the"> <h4>**Wow**</h4> </div> <div class="moon"> <h4>**Great**</h4> </div> </div> </div> </div> BUFFER; $doc = new DOMDocument(); $doc->loadHTML($buffer); $xpath = new DOMXPath($doc); /*** * example with iteration ***/ // all <div> tags with class="fly" $divs = $xpath->evaluate("//div[@class='fly']"); foreach ($divs as $div) { // the first data-original attribute of an <img> inside $div echo $xpath->evaluate("string(./img/@data-original)", $div), "<br/>\n"; // all <h4> tags anywhere inside the $div $h4s = $xpath->evaluate('.//h4[not(following-sibling::*//h4)]', $div); foreach ($h4s as $h4) { echo $h4->nodeValue, "<br/>\n"; } } echo "\n----------\n\n"; /*** * example with string evaluation ***/ echo <<<HTML {$xpath->evaluate("string(//div[@class='fly']/img/@data-original)")}<br/> {$xpath->evaluate("string(//div[@class='fly']//h4[not(following-sibling::*//h4)][1])")}<br/> {$xpath->evaluate("string(//div[@class='fly']//h4[not(following-sibling::*//h4)][2])")}<br/> <hr/> HTML; //

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.70.0120.00318.68
8.3.60.0040.01118.68
8.3.50.0110.01121.47
8.3.40.0110.00419.22
8.3.30.0110.00419.29
8.3.20.0040.00420.55
8.3.10.0080.00020.73
8.3.00.0030.00619.63
8.2.190.0040.01516.75
8.2.180.0130.00916.88
8.2.170.0040.01122.96
8.2.160.0090.00620.95
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0100.01026.16
8.2.120.0030.00720.96
8.2.110.0100.00021.50
8.2.100.0060.00617.98
8.2.90.0000.00817.84
8.2.80.0040.00419.58
8.2.70.0080.00017.75
8.2.60.0050.00518.05
8.2.50.0060.00318.07
8.2.40.0080.00018.41
8.2.30.0040.00418.38
8.2.20.0080.00018.15
8.2.10.0000.00718.51
8.2.00.0040.00418.02
8.1.280.0110.00425.92
8.1.270.0040.00822.50
8.1.260.0080.01226.35
8.1.250.0090.00928.09
8.1.240.0040.00422.56
8.1.230.0110.00021.34
8.1.220.0000.00818.26
8.1.210.0040.00419.18
8.1.200.0060.00317.50
8.1.190.0080.00017.85
8.1.180.0080.00018.10
8.1.170.0030.01018.76
8.1.160.0000.00719.30
8.1.150.0000.00819.25
8.1.140.0040.00417.79
8.1.130.0030.00518.14
8.1.120.0000.00717.83
8.1.110.0040.00417.86
8.1.100.0040.00417.88
8.1.90.0050.00317.71
8.1.80.0050.00217.86
8.1.70.0000.00717.75
8.1.60.0000.00817.97
8.1.50.0060.00317.87
8.1.40.0000.00817.77
8.1.30.0040.00417.88
8.1.20.0030.00517.97
8.1.10.0080.00017.81
8.1.00.0040.00417.94
8.0.300.0040.00420.59
8.0.290.0050.00317.25
8.0.280.0000.00718.91
8.0.270.0000.00817.62
8.0.260.0030.00317.58
8.0.250.0040.00417.31
8.0.240.0030.00317.28
8.0.230.0080.00017.45
8.0.220.0000.00717.36
8.0.210.0040.00417.29
8.0.200.0000.00717.32
8.0.190.0030.00617.27
8.0.180.0080.00017.38
8.0.170.0030.00717.41
8.0.160.0000.00717.36
8.0.150.0040.00417.30
8.0.140.0040.00417.27
8.0.130.0030.00313.77
8.0.120.0080.00017.34
8.0.110.0040.00417.24
8.0.100.0030.00517.40
8.0.90.0070.00017.35
8.0.80.0100.00717.32
8.0.70.0070.00017.39
8.0.60.0000.00817.41
8.0.50.0000.00817.35
8.0.30.0050.01517.49
8.0.20.0030.01617.55
8.0.10.0040.00417.36
8.0.00.0080.01017.31
7.4.330.0000.00515.42
7.4.320.0030.00316.87
7.4.300.0000.00616.80
7.4.290.0000.00716.95
7.4.280.0000.00816.95
7.4.270.0030.00316.84
7.4.260.0070.00016.90
7.4.250.0040.00416.90
7.4.240.0000.00816.90
7.4.230.0000.00816.79
7.4.220.0150.01517.12
7.4.210.0060.00917.00
7.4.200.0000.00716.88
7.4.160.0110.00616.98
7.4.150.0200.00717.40
7.4.140.0120.00917.86
7.4.130.0060.01117.01
7.4.120.0110.00816.88
7.4.110.0110.00617.05
7.4.100.0120.00616.86
7.4.90.0070.01016.72
7.4.80.0030.01619.39
7.4.70.0060.01216.84
7.4.60.0130.00516.68
7.4.50.0030.00617.02
7.4.40.0160.00617.05
7.4.30.0090.00916.74
7.4.00.0070.00714.91
7.3.330.0000.00513.50
7.3.320.0000.00613.50
7.3.310.0000.00716.64
7.3.300.0000.00716.57
7.3.290.0110.00616.60
7.3.280.0060.01016.69
7.3.270.0090.01417.40
7.3.260.0140.00316.67
7.3.250.0120.00816.86
7.3.240.0070.01116.70
7.3.230.0080.00816.88
7.3.210.0070.01116.82
7.3.200.0200.00419.39
7.3.190.0100.01317.01
7.3.180.0090.00916.66
7.3.170.0030.01416.62
7.3.160.0240.00016.80
7.3.10.0100.00716.86
7.3.00.0040.01216.66
7.2.330.0180.00616.83
7.2.320.0090.01217.20
7.2.310.0130.00617.05
7.2.300.0190.00316.72
7.2.290.0100.01217.02
7.2.130.0110.00817.04
7.2.120.0000.01116.92
7.2.110.0030.01017.22
7.2.100.0040.01117.05
7.2.90.0030.01217.14
7.2.80.0130.00716.92
7.2.70.0100.00017.03
7.2.60.0040.01316.90
7.2.50.0040.00816.89
7.2.40.0110.00416.83
7.2.30.0060.00617.06
7.2.20.0160.00017.10
7.2.10.0110.00317.00
7.2.00.0030.01218.43
7.1.250.0110.00015.92
7.1.240.0070.01015.65
7.1.230.0070.01016.05
7.1.220.0090.00615.65
7.1.210.0110.00715.90
7.1.200.0100.01315.67
7.1.190.0030.01015.92
7.1.180.0100.00715.79
7.1.170.0060.00916.03
7.1.160.0080.00416.03
7.1.150.0070.00715.94
7.1.140.0130.01015.64
7.1.130.0090.00316.12
7.1.120.0150.00316.12
7.1.110.0130.00715.71
7.1.100.0100.00717.02
7.1.90.0060.00315.81
7.1.80.0060.00315.91
7.1.70.0080.00616.76
7.1.60.0080.01017.60
7.1.50.0070.01016.53
7.1.40.0040.00816.06
7.1.30.0070.00715.91
7.1.20.0100.00615.84
7.1.10.0080.00015.85
7.1.00.0120.03519.31
7.0.330.0060.00915.35
7.0.320.0000.01515.39
7.0.310.0080.00615.45
7.0.300.0070.01115.39
7.0.290.0030.01215.31
7.0.280.0100.00615.27
7.0.270.0030.01315.64
7.0.260.0030.01315.36
7.0.250.0100.00715.53
7.0.240.0130.00315.36
7.0.230.0100.01015.63
7.0.220.0070.00715.58
7.0.210.0060.00615.56
7.0.200.0060.00716.07
7.0.190.0060.00615.73
7.0.180.0100.00715.60
7.0.170.0030.00615.52
7.0.160.0080.00815.78
7.0.150.0040.00715.41
7.0.140.0090.03218.81
7.0.130.0000.01415.45
7.0.120.0060.00615.53
7.0.110.0080.00315.51
7.0.100.0030.01315.61
7.0.90.0030.00615.39
7.0.80.0000.00915.49
7.0.70.0050.00515.55
7.0.60.0120.04217.76
7.0.50.0050.04516.87
7.0.40.0070.04217.04
7.0.30.0180.03517.02
7.0.20.0100.02716.85
7.0.10.0050.04616.90
7.0.00.0050.03016.85
5.6.380.0120.00614.55
5.6.370.0070.00714.46
5.6.360.0070.00714.63
5.6.350.0040.01114.36
5.6.340.0030.00714.34
5.6.330.0000.01414.46
5.6.320.0070.00314.02
5.6.310.0040.00414.59
5.6.300.0070.00714.49
5.6.290.0000.01414.41
5.6.280.0090.03717.64
5.6.270.0070.01014.34
5.6.260.0090.00614.37
5.6.250.0100.00314.20
5.6.240.0070.01114.43
5.6.230.0040.01114.64
5.6.220.0040.00814.28
5.6.210.0090.04017.41
5.6.200.0050.04316.47
5.6.190.0080.04517.62
5.6.180.0210.02017.51
5.6.170.0120.02417.42
5.6.160.0050.04517.44
5.6.150.0090.03316.42
5.6.140.0070.02116.39
5.6.130.0040.03716.48
5.6.120.0110.03817.63
5.6.110.0100.04017.75
5.6.100.0090.03517.61
5.6.90.0050.03417.61
5.6.80.0050.02417.27
5.6.70.0040.00814.13
5.6.60.0000.01113.99
5.6.50.0040.00714.63
5.6.40.0040.00714.39
5.6.30.0070.00414.38
5.6.20.0110.00414.11
5.6.10.0080.00614.21
5.6.00.0120.00014.18
5.5.380.0070.00411.04
5.5.370.0030.00910.97
5.5.360.0030.00611.00
5.5.350.0080.02515.77
5.5.340.0040.03614.53
5.5.330.0070.03515.75
5.5.320.0190.02515.64
5.5.310.0190.02715.83
5.5.300.0070.03714.49
5.5.290.0080.03414.52
5.5.280.0110.03816.07
5.5.270.0050.04715.90
5.5.260.0050.04316.00
5.5.250.0020.02715.91
5.5.240.0130.04115.61
5.5.230.0120.00010.63
5.5.220.0000.00610.87
5.5.210.0030.00610.81
5.5.200.0100.00311.23
5.5.190.0030.00710.99
5.5.180.0060.00310.90
5.5.170.0100.00311.12
5.5.160.0070.00311.08
5.5.150.0050.00510.83
5.5.140.0000.01010.90
5.5.130.0060.00611.03
5.5.120.0050.00210.89
5.5.110.0030.00911.26
5.5.100.0000.00711.04
5.5.90.0040.00411.14
5.5.80.0040.00711.11
5.5.70.0060.00310.80
5.5.60.0000.00511.10
5.5.50.0000.01011.16
5.5.40.0070.00711.21
5.5.30.0030.00910.99
5.5.20.0040.00710.89
5.5.10.0040.00511.10
5.5.00.0000.00811.04
5.4.450.0500.01915.21
5.4.440.0600.03115.16
5.4.430.0590.03415.27
5.4.420.0360.00115.22
5.4.410.0360.00315.21
5.4.400.0350.00214.91
5.4.390.0320.00615.05
5.4.380.0340.00115.06
5.4.370.0470.00014.95
5.4.360.0320.00415.22
5.4.350.0360.00314.89
5.4.340.0380.00315.10
5.4.330.0030.00710.81
5.4.320.0040.02311.75
5.4.310.0060.02211.92
5.4.300.0050.02011.79
5.4.290.0040.02411.73
5.4.280.0050.02411.76
5.4.270.0020.02611.74
5.4.260.0020.03011.62
5.4.250.0040.03111.91
5.4.240.0040.02011.80
5.4.230.0040.02411.66
5.4.220.0060.02111.70
5.4.210.0050.02911.81
5.4.200.0020.02411.81
5.4.190.0040.02111.89
5.4.180.0070.02511.70
5.4.170.0050.02711.75
5.4.160.0080.01911.93
5.4.150.0050.02211.82
5.4.140.0060.02211.70
5.4.130.0050.02111.74
5.4.120.0060.02111.37
5.4.110.0080.01711.49
5.4.100.0070.02411.65
5.4.90.0080.02711.67
5.4.80.0070.02711.56
5.4.70.0040.02211.51
5.4.60.0020.02511.51
5.4.50.0050.02311.48
5.4.40.0050.02211.56
5.4.30.0070.02111.53
5.4.20.0040.02611.59
5.4.10.0050.02311.57
5.4.00.0060.02111.34
5.3.290.0090.03611.88
5.3.280.0090.02511.68
5.3.270.0110.02111.70
5.3.260.0070.02111.79
5.3.250.0070.02711.76
5.3.240.0080.02411.66
5.3.230.0100.02811.77
5.3.220.0130.02011.65
5.3.210.0100.02211.70
5.3.200.0060.02511.63
5.3.190.0050.02411.67
5.3.180.0080.02011.72
5.3.170.0070.02511.80
5.3.160.0090.01711.76
5.3.150.0070.02011.78
5.3.140.0080.02011.70
5.3.130.0080.02511.63
5.3.120.0050.02311.68
5.3.110.0070.02411.62
5.3.100.0090.02211.37
5.3.90.0100.01911.47
5.3.80.0070.02211.39
5.3.70.0060.02811.36
5.3.60.0060.02711.43
5.3.50.0060.02311.34
5.3.40.0080.01911.40
5.3.30.0070.02011.36
5.3.20.0050.02211.21
5.3.10.0080.01911.07
5.3.00.0060.02211.06
5.2.170.0040.0199.82
5.2.160.0060.0179.82
5.2.150.0060.0179.82
5.2.140.0050.0189.81
5.2.130.0020.0239.79
5.2.120.0040.0209.79
5.2.110.0060.0209.80
5.2.100.0040.0199.80
5.2.90.0040.0249.80
5.2.80.0030.0249.79
5.2.70.0060.0179.80
5.2.60.0060.0279.77
5.2.50.0100.0219.76
5.2.40.0050.0199.74
5.2.30.0020.0219.73
5.2.20.0040.0239.73
5.2.10.0050.0189.69
5.2.00.0030.0239.63
5.1.60.0080.0149.27
5.1.50.0040.0169.26
5.1.40.0020.0179.26
5.1.30.0050.0149.43
5.1.20.0020.0169.44
5.1.10.0020.0179.30
5.1.00.0060.0149.18
5.0.50.0020.0148.51
5.0.40.0020.0158.44
5.0.30.0050.0188.35
5.0.20.0060.0108.34
5.0.10.0050.0128.32
5.0.00.0060.0218.32
4.4.90.0020.0117.47
4.4.80.0020.0097.46
4.4.70.0030.0107.46
4.4.60.0030.0137.46
4.4.50.0030.0137.47
4.4.40.0040.0167.44
4.4.30.0020.0107.46
4.4.20.0020.0127.51
4.4.10.0040.0097.51
4.4.00.0020.0177.46
4.3.110.0050.0147.42
4.3.100.0040.0117.42
4.3.90.0040.0087.40
4.3.80.0010.0177.38
4.3.70.0050.0097.40
4.3.60.0050.0087.40
4.3.50.0030.0097.40
4.3.40.0060.0127.35
4.3.30.0050.0086.74
4.3.20.0020.0126.73
4.3.10.0040.0096.71
4.3.00.0000.01213.38

preferences:
20.1 ms | 401 KiB | 5 Q