3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div class="somethingelse">content</div> <div class="product-fields"> <div class="product-field product-field-type-R"> <span class="product-fields-title-wrapper"><span class="product-fields-title"><strong>Related Products</strong></span> <span title="" class="hasTooltip" data-original-title="&lt;strong&gt;Related Products&lt;/strong&gt;&lt;br /&gt;COM_VIRTUEMART_RELATED_PRODUCTS_TIP"><img alt="Tooltip" src="/j34/media/system/images/tooltip.png"></span></span> <span class="product-field-display"><a target="blank" title="Test Product 1" href="/j34/index.php/shops/c1/t1-detail">Test Product 1</a></span><span class="product-field-desc">Custom prototype for related products</span> </div> <div class="mickmackusa">Not the drone you're looking for</div> <div class="product-field matrix-agent-smith product-field-type-R"> <span>Find them and destroy them</span> </div> </div> <div class="someothercontainer">Text</div> HTML; $getRelatedProduct = "Flashy, shiny, new"; libxml_use_internal_errors(true); $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $element = $dom->createElement('div', $getRelatedProduct); $xpath = new DOMXPath($dom); $nodes = $xpath->query("//div[contains(@class, 'product-fields')]/div[contains(@class, 'product-field') and contains(@class, 'product-field-type-R')]"); for ($i = $nodes->length - 1; $i >= 0; --$i) { // when removing nodes from DOM, work in reverse order for stability $node = $nodes->item($i); if ($i) { //$trailing_whitespace = $node->nextSibling; $node->parentNode->removeChild($node); // remove any qualifying element that IS NOT the first element //$trailing_whitespace->parentNode->removeChild($trailing_whitespace); // optionally remove line returns after removed tags } else { $node->parentNode->replaceChild($element, $node); // replace the first element with the generated element } } echo $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.70.0070.00716.86
8.3.60.0060.01218.43
8.3.50.0110.00416.90
8.3.40.0000.01519.26
8.3.30.0080.00818.92
8.3.20.0030.00619.56
8.3.10.0040.00421.83
8.3.00.0030.00522.10
8.2.180.0160.00616.88
8.2.170.0040.01122.96
8.2.160.0030.01020.72
8.2.150.0070.00324.18
8.2.140.0050.00524.66
8.2.130.0170.00326.16
8.2.120.0050.00321.59
8.2.110.0060.00322.44
8.2.100.0080.00418.16
8.2.90.0080.00018.16
8.2.80.0030.00617.97
8.2.70.0040.00418.00
8.2.60.0030.00618.00
8.2.50.0030.00617.75
8.2.40.0050.00318.25
8.2.30.0030.00518.41
8.2.20.0080.00318.40
8.2.10.0000.00818.43
8.2.00.0040.00419.66
8.1.280.0070.01025.92
8.1.270.0040.00422.48
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0060.00319.50
8.1.230.0040.00821.27
8.1.220.0040.00418.14
8.1.210.0060.00319.10
8.1.200.0030.00517.50
8.1.190.0090.00017.46
8.1.180.0080.00018.10
8.1.170.0030.00617.72
8.1.160.0000.00719.17
8.1.150.0000.00719.18
8.1.140.0060.00322.52
8.1.130.0000.00720.33
8.1.120.0050.00217.79
8.1.110.0000.00717.73
8.1.100.0000.00717.66
8.1.90.0040.00417.65
8.1.80.0040.00417.66
8.1.70.0000.00917.77
8.1.60.0040.00417.90
8.1.50.0000.00717.70
8.1.40.0030.00517.77
8.1.30.0040.00417.93
8.1.20.0060.00317.97
8.1.10.0000.00817.84
8.1.00.0030.00617.90
8.0.300.0070.00020.14
8.0.290.0000.00817.38
8.0.280.0050.00218.88
8.0.270.0030.00517.51
8.0.260.0000.00718.80
8.0.250.0080.00017.42
8.0.240.0030.00717.42
8.0.230.0080.00017.32
8.0.220.0000.00817.26
8.0.210.0040.00417.25
8.0.200.0000.00917.23
8.0.190.0070.00017.17
8.0.180.0030.00517.30
8.0.170.0000.00817.20
8.0.160.0080.00017.23
8.0.150.0090.00417.13
8.0.140.0050.00217.19
8.0.130.0000.00613.71
8.0.120.0040.00417.23
8.0.110.0040.00417.20
8.0.100.0080.00017.27
8.0.90.0000.00717.11
8.0.80.0030.01317.26
8.0.70.0040.00417.04
8.0.60.0000.00817.09
8.0.50.0030.00517.18
8.0.30.0100.00917.40
8.0.20.0090.01017.48
8.0.10.0050.00217.35
8.0.00.0090.01317.05
7.4.330.0000.00517.04
7.4.320.0000.00616.83
7.4.300.0070.00016.84
7.4.290.0070.00016.89
7.4.280.0070.00016.70
7.4.270.0040.00416.88
7.4.260.0030.00916.76
7.4.250.0000.00716.64
7.4.240.0020.00516.91
7.4.230.0000.00816.66
7.4.220.0060.00317.00
7.4.210.0110.00516.88
7.4.200.0000.00717.02
7.4.160.0120.00516.96
7.4.140.0090.01017.86
7.4.130.0180.00016.85
7.4.120.0140.00716.86
7.4.110.0110.01116.93
7.4.100.0210.00317.02
7.4.90.0120.00616.86
7.4.80.0080.00919.39
7.4.70.0100.00616.65
7.4.60.0140.00716.70
7.4.50.0030.01016.57
7.4.40.0080.00816.61
7.4.00.0110.00615.42
7.3.330.0000.00713.54
7.3.320.0030.00313.38
7.3.310.0030.00316.69
7.3.300.0040.00416.57
7.3.290.0000.00716.59
7.3.280.0080.00916.69
7.3.260.0110.00716.82
7.3.240.0110.00616.75
7.3.230.0100.01316.89
7.3.210.0070.01016.84
7.3.200.0080.00816.71
7.3.190.0090.01416.81
7.3.180.0100.01016.77
7.3.170.0060.01216.72
7.3.160.0140.00716.71
7.3.120.0100.01015.02
7.3.110.0100.01015.01
7.3.100.0040.00715.04
7.3.90.0030.00614.90
7.3.80.0100.00714.98
7.3.70.0040.01114.96
7.3.60.0040.00714.88
7.3.50.0160.00314.81
7.3.40.0070.01014.62
7.3.30.0070.01114.82
7.3.20.0030.01016.71
7.3.10.0110.00316.81
7.3.00.0100.00716.83
7.2.330.0070.01117.04
7.2.320.0070.01017.16
7.2.310.0070.01017.16
7.2.300.0080.00817.20
7.2.290.0130.01016.91
7.2.250.0030.01015.22
7.2.240.0070.01315.44
7.2.230.0030.01415.39
7.2.220.0040.01115.27
7.2.210.0070.01015.12
7.2.200.0080.00815.27
7.2.190.0110.00015.29
7.2.180.0030.01315.40
7.2.170.0100.01015.30
7.2.120.0800.01514.77
7.2.110.0860.00715.08
7.2.100.0840.01214.76
7.2.90.1130.01015.00
7.2.80.1610.01415.00
7.2.70.1070.00315.22
7.2.60.0870.01015.20
7.2.50.0670.01014.84
7.2.40.0710.01015.22
7.2.30.0580.01315.09
7.2.20.0600.00314.82
7.2.10.1230.00514.88
7.2.00.0690.00315.07
7.1.330.0040.01116.08
7.1.320.0030.00915.75
7.1.310.0060.01216.12
7.1.300.0030.01015.93
7.1.290.0070.01015.98
7.1.280.0070.01015.93
7.1.270.0000.01116.00
7.1.260.0040.00416.01
7.1.240.1020.00613.84
7.1.230.1050.00714.18
7.1.220.0580.00713.95
7.1.210.0470.00713.94
7.1.200.1040.00714.01
7.1.190.1300.00614.15
7.1.180.0660.01013.82
7.1.170.0740.00313.94
7.1.160.0530.00714.17
7.1.150.0600.00313.79
7.1.140.0490.01314.00
7.1.130.0640.01014.24
7.1.120.0550.01013.93
7.1.110.0600.00414.16
7.1.100.0790.01013.82
7.1.90.0420.01514.01
7.1.80.0780.01413.96
7.1.70.0610.00613.50
7.1.60.0550.00313.87
7.1.50.0730.01313.93
7.1.40.0500.00713.93
7.1.30.1010.01013.84
7.1.20.0640.01313.84
7.1.10.0780.01113.82
7.1.00.1690.00713.84
5.6.380.0140.00414.23

preferences:
73.27 ms | 401 KiB | 5 Q