3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* This function DOES NOT validate the $bbcode string to contain a balanced number of opening & closing tags. This funcion DOES check that there are enough closing tags to conclude a targeted opening tag. */ function omit_user_quotes($bbcode, $user) { $substrings = preg_split('~(\[/?quote[^]]*\])~', $bbcode, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $opens = 0; // necessary declaration to avoid Notice when no quote tags in $bbcode string foreach ($substrings as $index => $substring) { if (!isset($start) && $substring == "[quote={$user}]") { // found targeted user's first opening quote $start = $index; // disqualify the first if statement and start searching for end tag $opens = 1; // $opens counts how many end tags are required to conclude quote block } elseif (isset($start)) { if (strpos($substring, '[quote=') !== false) { // if a nested opening quote tag is found ++$opens; // increment and continue looking for closing quote tags } elseif (strpos($substring, '[/quote]') !== false) { // if a closing quote tag is found --$opens; // decrement and check for quote tag conclusion or error if (!$opens) { // if $opens is zero ($opens can never be less than zero) $substrings = array_diff_key($substrings, array_flip(range($start, $index))); // slice away unwanted elements from input array unset($start); // re-qualify the first if statement to allow the process to repeat } } } } if ($opens) { // if $opens is positive return 'Error due to opening/closing tag imbalance (too few end tags)'; } else { return trim(implode($substrings)); // trims the whitespaces on either side of $bbcode string as feature } } /* Single unwanted quote with nested innocent quote: */ /*$bbcode='[quote=testuser] [quote=anotheruser]a sdasdsa dfv rdfgrgre gzdf vrdg[/quote] sdfsd fdsf dsf sdf[/quote] the rest of the test'; */ /* output: the rest of the test */ /* Complex battery of unwanted, wanted, and nested quotes: */ $bbcode = '[quote=mickmackusa]Keep this[/quote] [quote=testuser]Don\'t keep this because [quote=mickmackusa]said don\'t do it[/quote] ... like that\'s a good reason [quote=NaughtySquid] It\'s tricky business, no?[/quote] [quote=nester][quote=nesty][quote=nested][/quote][/quote][/quote] [/quote] Let\'s remove a second set of quotes [quote=testuser]Another quote block[/quote] [quote=mickmackusa]Let\'s do a third quote inside of my quote... [quote=testuser]Another quote block[/quote] [/quote] This should be good, but What if [quote=testuser]quotes himself [quote=testuser] inside of his own[/quote] quote[/quote]?'; /* No quotes: */ //$bbcode='This has no bbcode quote tags in it.'; /* output: This has no bbcode quote tags in it. */ /* Too few end quote tags by innocent user: (No flag is raised because the targeted user has not quoted any text) */ //$bbcode='This [quote=mickmackusa] has not end tag.'; /* output: This [quote=mickmackusa] has not end tag. */ /* Too few end quote tags by unwanted user: */ //$bbcode='This [quote=testuser] has not end tag.'; /* output: Error due to opening/closing tag imbalance (too few end tags) */ /* Too many end quote tags by unwanted user: (No flag is raised because the function does not validate the bbcode text as fully balanced) */ //$bbcode='This [quote=testuser] has too many end[/quote] tags.[/quote]'; /* output: This tags.[/quote] */ $user = 'testuser'; echo omit_user_quotes($bbcode, $user); // omit a single user's quote blocks /* Or if you want to omit quote blocks from multiple users, you can use a loop: $users = ['mickmackusa', 'NaughtySquid']; foreach ($users as $user) { $bbcode = omit_user_quotes($bbcode, $user); } echo $bbcode; */

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.80.0030.00719.36
8.3.70.0040.01416.75
8.3.60.0140.00018.55
8.3.50.0090.00616.50
8.3.40.0100.00718.92
8.3.30.0150.00618.98
8.3.20.0040.00424.18
8.3.10.0050.00324.66
8.3.00.0080.00026.16
8.2.200.0090.00018.88
8.2.190.0060.01216.63
8.2.180.0080.00625.92
8.2.170.0170.00018.94
8.2.160.0070.00722.96
8.2.150.0050.00225.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0040.00419.63
8.2.110.0070.00322.20
8.2.100.0080.00317.84
8.2.90.0040.00419.34
8.2.80.0040.00418.95
8.2.70.0000.00817.75
8.2.60.0050.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00820.07
8.2.30.0080.00018.02
8.2.20.0000.00718.17
8.2.10.0070.00019.36
8.2.00.0000.00819.31
8.1.290.0030.00630.84
8.1.280.0090.00625.92
8.1.270.0080.00023.99
8.1.260.0060.00326.35
8.1.250.0030.00528.09
8.1.240.0070.00320.39
8.1.230.0070.00317.77
8.1.220.0030.00617.74
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0030.00517.48
8.1.180.0030.00518.10
8.1.170.0050.00318.87
8.1.160.0000.00718.87
8.1.150.0000.00718.92
8.1.140.0000.00718.97
8.1.130.0080.00017.60
8.1.120.0000.00717.65
8.1.110.0040.00417.53
8.1.100.0070.00417.59
8.1.90.0000.00717.56
8.1.80.0050.00517.45
8.1.70.0100.00017.63
8.1.60.0000.00717.66
8.1.50.0080.00017.69
8.1.40.0040.00417.58
8.1.30.0050.00317.65
8.1.20.0000.00917.81
8.1.10.0030.00617.72
8.1.00.0080.00017.60
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0000.00718.36
8.0.270.0050.00218.19
8.0.260.0030.00316.98
8.0.250.0030.00317.02
8.0.240.0030.00317.12
8.0.230.0070.00017.14
8.0.220.0040.00417.02
8.0.210.0070.00016.95
8.0.200.0070.00017.15
8.0.190.0040.00417.00
8.0.180.0040.00717.13
8.0.170.0000.00817.06
8.0.160.0030.00617.02
8.0.150.0070.00317.06
8.0.140.0000.00716.91
8.0.130.0000.00513.53
8.0.120.0000.00816.99
8.0.110.0000.00717.04
8.0.100.0040.00416.94
8.0.90.0040.00416.94
8.0.80.0110.00716.97
8.0.70.0130.01017.10
8.0.60.0190.00616.88
8.0.50.0150.00916.96
8.0.30.0160.00817.07
8.0.20.0140.01017.11
8.0.10.0140.01017.07
8.0.00.0100.01117.11
7.4.330.0050.00015.55
7.4.320.0040.00416.77
7.4.300.0030.00316.80
7.4.290.0040.00416.73
7.4.280.0130.00016.59
7.4.270.0000.00816.64
7.4.260.0030.00313.54
7.4.250.0000.00716.75
7.4.240.0050.00216.85
7.4.230.0030.00316.65
7.4.220.0040.00416.64
7.4.210.0140.01016.77
7.4.200.0230.00016.73
7.4.190.0190.00916.83
7.4.180.0130.00916.76
7.4.160.0210.01216.71
7.4.150.0100.01316.70
7.4.140.0160.00816.73
7.4.130.0200.00316.92
7.4.120.0130.01016.77
7.4.110.0220.00416.67
7.4.100.0220.00316.90
7.4.90.0140.01016.78
7.4.80.0160.00816.69
7.4.70.0130.01316.86
7.4.60.0190.00716.84
7.4.50.0120.01216.79
7.4.40.0040.01916.64
7.4.30.0100.01316.91
7.4.20.0100.01716.66
7.4.10.0090.00916.70
7.4.00.0130.00516.72
7.3.330.0070.00016.55
7.3.320.0000.00513.57
7.3.310.0070.00016.55
7.3.300.0000.00816.43
7.3.290.0150.00816.52
7.3.280.0100.00716.54
7.3.270.0030.01516.60
7.3.260.0130.00316.52
7.3.250.0190.00316.57
7.3.240.0030.01916.57
7.3.230.0160.00416.54
7.3.220.0120.00816.52
7.3.210.0160.00516.48
7.3.200.0160.00416.46
7.3.190.0060.01216.47
7.3.180.0070.01716.51
7.3.170.0200.01216.50
7.3.160.0180.01416.48
7.3.150.0180.00916.49
7.3.140.0210.00416.57
7.3.130.0240.00316.41
7.3.120.0150.00916.48
7.3.110.0130.01316.44
7.3.100.0200.01216.44
7.3.90.0170.00816.84
7.3.80.0120.01216.55
7.3.70.0160.01316.62
7.3.60.0390.00616.76
7.3.50.0160.01216.58
7.3.40.0150.01516.65
7.3.30.0250.00016.70
7.3.20.0220.00616.73
7.3.10.0150.01116.64
7.3.00.0230.00416.63

preferences:
28.66 ms | 401 KiB | 5 Q