3v4l.org

run code in 300+ PHP versions simultaneously
<?php $post_content = "<p>There are 14 more days until our <a href=\"/somepage.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"join us\">holiday special</a> so come join us!</p>"; $dom = new DOMDocument(); $dom->loadHTML($post_content); $xpath = new DOMXPath($dom); $all_text_nodes = $xpath->query("//text()"); $words_left = 9; // reduced for this text to cut off at "holiday" foreach( $all_text_nodes as $text_node) { $text = $text_node->textContent; $words = explode(" ", $text); // TODO: maybe preg_split on /\s/ to support more whitespace types $word_count = count($words); if( $word_count < $words_left) { $words_left -= $word_count; continue; } // reached the threshold $words_that_fit = implode(" ", array_slice($words, 0, $words_left)); // If the above TODO is implemented, this will need to be adjusted to keep the specific whitespace characters $text_node->textContent = $words_that_fit; $remove_after = $text_node; while( $remove_after->parentNode) { while( $remove_after->nextSibling) { $remove_after->parentNode->removeChild($remove_after->nextSibling); } $remove_after = $remove_after->parentNode; } break; } $output = substr($dom->saveHTML($dom->getElementsByTagName("body")->item(0)), strlen("<body>"), -strlen("</body>")); echo $output;

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.130.0040.00418.55
8.3.120.0090.00019.44
8.3.110.0060.00320.94
8.3.100.0030.00624.06
8.3.90.0030.00526.77
8.3.80.0030.00617.00
8.3.70.0070.00717.25
8.3.60.0140.00416.88
8.3.50.0140.00524.64
8.3.40.0100.00619.58
8.3.30.0060.01018.96
8.3.20.0060.00324.18
8.3.10.0060.00324.66
8.3.00.0080.00026.16
8.2.250.0030.00617.29
8.2.240.0000.00817.47
8.2.230.0030.00622.58
8.2.220.0060.00337.54
8.2.210.0030.00526.77
8.2.200.0030.00616.88
8.2.190.0030.02116.88
8.2.180.0100.01025.92
8.2.170.0040.01519.33
8.2.160.0070.01022.96
8.2.150.0000.00825.66
8.2.140.0050.00324.66
8.2.130.0020.00526.16
8.2.120.0050.00326.35
8.2.110.0100.00022.81
8.2.100.0120.00418.16
8.2.90.0040.00418.00
8.2.80.0040.00419.08
8.2.70.0050.00518.00
8.2.60.0080.00018.28
8.2.50.0050.00318.05
8.2.40.0000.00820.38
8.2.30.0030.00618.63
8.2.20.0000.00818.46
8.2.10.0030.00619.64
8.2.00.0050.00219.65
8.1.300.0060.01316.79
8.1.290.0100.00018.88
8.1.280.0110.00825.92
8.1.270.0110.00023.99
8.1.260.0040.00428.09
8.1.250.0050.00328.09
8.1.240.0090.00021.38
8.1.230.0090.00318.20
8.1.220.0000.00918.16
8.1.210.0050.00318.77
8.1.200.0000.00917.63
8.1.190.0050.00317.73
8.1.180.0040.00418.10
8.1.170.0040.00419.00
8.1.160.0030.00519.25
8.1.150.0100.00019.25
8.1.140.0050.00219.18
8.1.130.0040.00420.46
8.1.120.0030.00517.86
8.1.110.0000.00817.76
8.1.100.0100.00017.71
8.1.90.0040.00317.83
8.1.80.0070.00317.88
8.1.70.0000.00717.82
8.1.60.0050.00317.84
8.1.50.0070.00317.76
8.1.40.0040.00417.82
8.1.30.0050.00517.96
8.1.20.0070.00817.91
8.1.10.0050.00417.80
8.1.00.0050.00317.90
8.0.300.0000.00718.77
8.0.290.0030.00517.00
8.0.280.0070.00018.79
8.0.270.0040.00418.35
8.0.260.0000.00718.93
8.0.250.0040.00717.35
8.0.240.0040.00417.20
8.0.230.0030.00517.20
8.0.220.0040.00417.26
8.0.210.0040.00417.17
8.0.200.0080.00017.25
8.0.190.0070.00017.22
8.0.180.0030.00517.20
8.0.170.0030.00617.23
8.0.160.0040.00417.16
8.0.150.0040.00417.23
8.0.140.0040.00417.16
8.0.130.0050.00013.69
8.0.120.0040.00417.15
8.0.110.0050.00217.05
8.0.100.0040.00417.18
8.0.90.0000.00917.21
8.0.80.0080.01217.26
8.0.70.0030.00517.17
8.0.60.0040.00417.40
8.0.50.0050.00316.98
8.0.30.0130.00317.52
8.0.20.0080.01317.28
8.0.10.0040.00417.43
8.0.00.0100.01316.95
7.4.330.0000.00515.55
7.4.320.0000.00616.98
7.4.300.0030.00316.96
7.4.290.0000.00816.88
7.4.280.0040.00416.84
7.4.270.0000.00716.73
7.4.260.0050.00013.62
7.4.250.0000.00716.84
7.4.240.0010.00616.98
7.4.230.0000.00817.02
7.4.220.0040.00316.93
7.4.210.0060.00816.97
7.4.200.0040.00416.64
7.4.130.0110.00716.79
7.4.120.0100.01317.02
7.4.110.0120.00616.86
7.4.100.0140.00716.74
7.4.90.0120.00616.76
7.4.80.0090.00919.39
7.4.70.0100.00616.94
7.4.60.0120.00616.84
7.4.50.0110.01116.66
7.4.40.0100.00716.60
7.4.30.0030.01416.67
7.4.20.0050.01116.84
7.4.10.0130.01016.80
7.4.00.0070.01016.99
7.3.330.0030.00316.74
7.3.320.0030.00313.49
7.3.310.0000.00716.71
7.3.300.0000.00716.66
7.3.290.0000.00816.57
7.3.260.0030.02016.95
7.3.240.0070.00916.84
7.3.230.0110.01116.72
7.3.210.0100.00916.71
7.3.200.0050.01116.60
7.3.190.0160.00716.81
7.3.180.0090.00816.79
7.3.170.0080.00816.79
7.3.160.0000.01616.65
7.3.150.0000.01716.75
7.3.140.0000.01616.88
7.3.130.0070.01016.82
7.3.120.0120.00316.43
7.3.110.0110.00716.88
7.3.100.0100.00716.69
7.3.90.0100.00616.75
7.3.80.0100.00716.84
7.3.70.0130.00316.56
7.3.60.0130.00316.63
7.3.50.0090.00916.87
7.3.40.0100.00716.55
7.3.30.0110.00716.69
7.3.20.0060.01016.54
7.3.10.0060.01216.53
7.3.00.0100.00716.62
7.2.330.0090.01216.75
7.2.310.0060.01217.09
7.2.300.0100.00616.86
7.2.290.0150.00316.76
7.2.280.0030.01517.09
7.2.270.0030.01416.89
7.2.260.0090.00916.82
7.2.250.0170.00016.88
7.2.240.0120.00817.05
7.2.230.0100.00716.85
7.2.220.0150.00317.16
7.2.210.0070.01016.94
7.2.200.0040.01316.82
7.2.190.0110.00716.84
7.2.180.0110.00616.89
7.2.170.0090.00916.62
7.2.160.0110.00616.82
7.2.150.0150.00316.80
7.2.140.0110.00716.72
7.2.130.0130.00716.92
7.2.120.0060.01316.88
7.2.110.0100.00716.95
7.2.100.0140.00316.97
7.2.90.0150.00316.91
7.2.80.0090.00917.20
7.2.70.0090.00916.78
7.2.60.0070.01016.96
7.2.50.0000.01817.06
7.2.40.0150.00416.96
7.2.30.0160.00316.96
7.2.20.0120.00616.87
7.2.10.0090.00917.06
7.2.00.0090.00916.89

preferences:
26.2 ms | 403 KiB | 5 Q