3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = /*$_GET['input'];*/ "Timothy Gentet-O'Brien"; $simpleBuilder = simpleBuilder($string); $advancedBuilder = advancedBuilder($simpleBuilder); echo "<script>console.log('advancedBuilder: ' + advancedBuilder);</script>"; echo "\r\n"; echo $advancedBuilder; // simpleBuilder() takes in an arrray of strings or a comma separated string, this should return // an Array of basic RegEx's function simpleBuilder($input) { // Check to see if it is an array, if it is not then we use .split(',') to convert it to an array. $input = is_array($input) ? $input : explode(',', $input); $simpleRegEx = []; // Iterate over all of the values in the array. for ($i = 0; $i < count($input); $i++) { // Set simpleRegEx[$i] to '' to ensure the code doesn't set it to "undefinedXXXX" $simpleRegEx[$i] = ''; // Run ltrim() and rtrim() on the current string ton ensure we have to extra and unneeded white spaces. $input[$i] = ltrim(rtrim($input[$i])); // Iterate over the current string to work out what each character is and assign simpleRegEx[$i] the relevant RegEx character for ($j = 0; $j < count($input[$i]); $j++) { if (preg_match('/[ \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\s'; } else if (preg_match('/[0-9]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\d'; } else if (preg_match('/[A-Za-z0-9_]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\w'; } else if (preg_match('/[^A-Za-z0-9_]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\W'; } else if (preg_match('/[^ \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\S'; } } } // Return the completed Array, which should look something like: ['\w\w\w\w\d\d\d','\w\w\w'] return $simpleRegEx; } // advancedBuilder() takes the output from simpleBuilder(), which is an Array of RegEx Strings, this should return // a more Array of complex set of RegEx's function advancedBuilder($simpleRegEx) { $prev; $curr; $next; $rcount = 1; $advancedRegex = []; // Iterate over the array for ($t = 0; $t < count($simpleRegEx); $t++) { // Again set advancedRegex[$t] to '' to ensure the code doesn't set it to "undefinedXXXX" $advancedRegex[$t] = ''; // Iterate over the current string, check the current, next and previous characters to // calculate whether or not we should be joining these, if everything if good, it should // then add the RegEx character '\d' and work out how many times this appears, it should // then output something like: '\d{4}'. for ($s = 0; $s < count($simpleRegEx[$t]); $s += 2) { $curr = $simpleRegEx[$t][$s] + $simpleRegEx[$t][$s + 1]; $next = $simpleRegEx[$t][$s + 2] + $simpleRegEx[$t][$s + 3]; $prev = $simpleRegEx[$t][$s - 2] + $simpleRegEx[$t][$s - 1]; if ($curr == $next) { if ($prev != $curr) { $advancedRegex[$t] += $curr; } $rcount += 1; } else { $advancedRegex[$t] += ($rcount == 1 ? $curr : '{' + $rcount + '}'); $rcount = 1; } } } // The Array of RegEx's, this should look something like: ["\w{7}\d{3}", "\w{3}"] // so we use .join('|') to add in an OR operator and add a caret and a dollar symbol // to show the start and end of the newly formed string to return a full RegEx $advancedRegex = '^' + join('|', $advancedRegex) + '$'; return $advancedRegex; } ?>

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.60.0000.01616.63
8.3.50.0110.00721.11
8.3.40.0120.00318.97
8.3.30.0170.00318.79
8.3.20.0040.00420.39
8.3.10.0050.00323.48
8.3.00.0070.00321.91
8.2.180.0110.00416.63
8.2.170.0140.00322.96
8.2.160.0030.00922.26
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0060.00317.63
8.2.110.0070.00322.20
8.2.100.0110.00017.63
8.2.90.0000.00819.05
8.2.80.0030.00617.97
8.2.70.0030.00517.63
8.2.60.0050.00317.93
8.2.50.0000.00818.07
8.2.40.0000.00821.16
8.2.30.0030.00519.82
8.2.20.0040.00417.70
8.2.10.0020.00518.04
8.2.00.0030.00518.04
8.1.280.0090.00625.92
8.1.270.0000.00724.66
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0060.00323.77
8.1.230.0060.00617.48
8.1.220.0040.00417.78
8.1.210.0040.00718.77
8.1.200.0030.00617.35
8.1.190.0060.00317.35
8.1.180.0050.00318.10
8.1.170.0040.00418.71
8.1.160.0000.00722.00
8.1.150.0080.00018.90
8.1.140.0030.00617.51
8.1.130.0040.00417.71
8.1.120.0040.00417.37
8.1.110.0040.00417.36
8.1.100.0030.00617.54
8.1.90.0070.00017.33
8.1.80.0040.00317.41
8.1.70.0040.00417.41
8.1.60.0040.00417.57
8.1.50.0090.00017.54
8.1.40.0070.00417.48
8.1.30.0090.00017.62
8.1.20.0030.00617.68
8.1.10.0040.00417.44
8.1.00.0040.00417.53
8.0.300.0000.00718.77
8.0.290.0040.00416.75
8.0.280.0030.00318.38
8.0.270.0040.00417.17
8.0.260.0000.00717.18
8.0.250.0000.00816.89
8.0.240.0040.00416.98
8.0.230.0000.00816.96
8.0.220.0040.00416.78
8.0.210.0000.00716.80
8.0.200.0040.00416.85
8.0.190.0030.00616.96
8.0.180.0020.00516.88
8.0.170.0060.00616.91
8.0.160.0040.00417.04
8.0.150.0030.00516.98
8.0.140.0000.00716.85
8.0.130.0030.00313.43
8.0.120.0040.00416.84
8.0.110.0000.00716.79
8.0.100.0050.00216.88
8.0.90.0000.00716.93
8.0.80.0160.00717.02
8.0.70.0040.00417.04
8.0.60.0050.00316.86
8.0.50.0050.00217.00
8.0.30.0150.00317.12
8.0.20.0100.01017.40
8.0.10.0050.00317.12
8.0.00.0080.01216.81
7.4.330.0030.00315.08
7.4.320.0060.00016.68
7.4.300.0000.00716.63
7.4.290.0080.00016.84
7.4.280.0030.00616.86
7.4.270.0000.00716.79
7.4.260.0000.00716.76
7.4.250.0000.00716.69
7.4.240.0040.00316.80
7.4.230.0000.00716.87
7.4.220.0090.00916.85
7.4.210.0070.00816.82
7.4.200.0000.00716.70
7.4.160.0060.01116.89
7.4.150.0060.01117.40
7.4.140.0120.00717.86
7.4.130.0090.01316.79
7.4.120.0140.00516.83
7.4.110.0060.01216.71
7.4.100.0110.01416.59
7.4.90.0120.00416.79
7.4.80.0060.01319.39
7.4.70.0060.01016.75
7.4.60.0070.01016.73
7.4.50.0030.00716.67
7.4.40.0090.00916.69
7.4.30.0110.01116.47
7.4.10.0070.01115.06
7.4.00.0070.01115.24
7.3.330.0060.00013.37
7.3.320.0060.00013.66
7.3.310.0030.00316.64
7.3.300.0030.00316.45
7.3.290.0120.01016.58
7.3.280.0090.01016.57
7.3.270.0000.02117.40
7.3.260.0130.01016.64
7.3.250.0100.01216.75
7.3.240.0000.01616.84
7.3.230.0100.01416.87
7.3.210.0100.00716.70
7.3.200.0100.00716.58
7.3.190.0000.02016.71
7.3.180.0130.00316.80
7.3.170.0110.01116.74
7.3.160.0060.01616.79
7.3.130.0130.00415.26
7.3.120.0080.00815.13
7.3.110.0080.01114.97
7.3.100.0080.00914.94
7.3.90.0080.00615.10
7.3.80.0060.00815.11
7.3.70.0030.01014.98
7.3.60.0100.00215.08
7.3.50.0120.00215.01
7.3.40.0080.00515.14
7.3.30.0110.00615.11
7.3.20.0040.01016.83
7.3.10.0050.00916.74
7.3.00.0050.00816.86
7.2.330.0130.00516.66
7.2.320.0060.01216.90
7.2.310.0060.00916.99
7.2.300.0150.00816.83
7.2.290.0090.00916.96
7.2.260.0060.01015.34
7.2.250.0060.01315.13
7.2.240.0060.01015.21
7.2.230.0060.01015.34
7.2.220.0080.01015.31
7.2.210.0080.00615.16
7.2.200.0090.00815.38
7.2.190.0070.00815.14
7.2.180.0050.00915.25
7.2.170.0090.00415.33
7.2.160.0100.00615.21
7.2.150.0040.01417.12
7.2.140.0050.00917.12
7.2.130.0120.00117.15
7.2.120.0020.01317.20
7.2.110.0030.01217.11
7.2.100.0050.01116.93
7.2.90.0070.00717.22
7.2.80.0080.00517.24
7.2.70.0050.00917.29
7.2.60.0060.00917.05
7.2.50.0020.01517.13
7.2.40.0030.00817.26
7.2.30.0060.00917.21
7.2.20.0080.00217.13
7.2.10.0040.01017.13
7.2.00.0040.01117.89
7.1.330.0040.01015.92
7.1.320.0070.00816.04
7.1.310.0090.00516.04
7.1.300.0070.00715.93
7.1.290.0050.00816.10
7.1.280.0030.01115.93
7.1.270.0020.01315.99
7.1.260.0050.00916.07
7.1.250.0040.00715.85
7.1.240.0050.00916.04
7.1.230.0040.00916.08
7.1.220.0050.01016.13
7.1.210.0050.00815.84
7.1.200.0060.00715.90
7.1.190.0070.01016.01
7.1.180.0030.01116.01
7.1.170.0020.01316.07
7.1.160.0060.00915.94
7.1.150.0020.01116.04
7.1.140.0060.00616.02
7.1.130.0090.00615.97
7.1.120.0030.01415.95
7.1.110.0100.00615.89
7.1.100.0040.00916.60
7.1.90.0060.00616.11
7.1.80.0050.00816.11
7.1.70.0050.00916.48
7.1.60.0060.01217.09
7.1.50.0060.01016.45
7.1.40.0040.00915.70
7.1.30.0070.00915.92
7.1.20.0050.00816.00
7.1.10.0070.00715.96
7.1.00.0090.02817.97
7.0.330.0050.00615.43
7.0.320.0070.00815.47
7.0.310.0050.00515.67
7.0.300.0080.00815.64
7.0.290.0100.00515.49
7.0.280.0040.00615.67
7.0.270.0070.00515.65
7.0.260.0070.00615.57
7.0.250.0050.00815.53
7.0.240.0070.00815.61
7.0.230.0070.00615.41
7.0.220.0080.00615.56
7.0.210.0030.01015.63
7.0.200.0150.00915.93
7.0.190.0070.00515.64
7.0.180.0080.00815.59
7.0.170.0100.00415.72
7.0.160.0050.00915.70
7.0.150.0010.00815.70
7.0.140.0090.00715.70
7.0.130.0050.00915.59
7.0.120.0020.00915.61
7.0.110.0000.01515.61
7.0.100.0080.00715.55
7.0.90.0100.00515.60
7.0.80.0120.00515.72
7.0.70.0070.00615.72
7.0.60.0110.02817.12
7.0.50.0070.03316.44
7.0.40.0040.03615.86
7.0.30.0110.01915.83
7.0.20.0140.03115.88
7.0.10.0060.02315.85
7.0.00.0080.03315.84
5.6.400.0070.00714.39
5.6.390.0040.00914.72
5.6.380.0050.00814.63
5.6.370.0080.00714.54
5.6.360.0030.01014.45
5.6.350.0030.01314.62
5.6.340.0020.01014.44
5.6.330.0070.00714.59
5.6.320.0040.00614.41
5.6.310.0040.01314.68
5.6.300.0080.00614.41
5.6.290.0030.00814.59
5.6.280.0020.02316.71
5.6.270.0040.00914.46
5.6.260.0050.00914.40
5.6.250.0090.00914.62
5.6.240.0050.00914.55
5.6.230.0100.00514.51
5.6.220.0040.00914.47
5.6.210.0050.01916.59
5.6.200.0050.01915.88
5.6.190.0030.02716.42
5.6.180.0150.01916.45
5.6.170.0100.02516.50
5.6.160.0110.03216.44
5.6.150.0120.02615.75
5.6.140.0040.03215.77
5.6.130.0080.03015.71
5.6.120.0110.02816.70
5.6.110.0090.03116.72
5.6.100.0060.02816.73
5.6.90.0060.02616.68
5.6.80.0080.01516.45
5.6.70.0030.00914.55
5.6.60.0060.00714.25
5.6.50.0040.00914.31
5.6.40.0050.01014.45
5.6.30.0060.00614.27
5.6.20.0050.00714.59
5.6.10.0060.00714.63
5.6.00.0030.01214.49
5.5.380.0080.00514.32
5.5.370.0080.00914.57
5.5.360.0120.00514.55
5.5.350.0120.02516.41
5.5.340.0090.03015.63
5.5.330.0080.02116.40
5.5.320.0160.02016.51
5.5.310.0150.03016.46
5.5.300.0030.01815.66
5.5.290.0090.02915.53
5.5.280.0050.02016.50
5.5.270.0030.02116.81
5.5.260.0110.02816.52
5.5.250.0060.02416.57
5.5.240.0070.02116.33
5.5.230.0080.00614.28
5.5.220.0110.00314.42
5.5.210.0040.01014.31
5.5.200.0000.01214.47
5.5.190.0070.00814.49
5.5.180.0030.00814.49
5.5.170.0050.01114.26
5.5.160.0100.00514.46
5.5.150.0100.00514.38
5.5.140.0070.00614.21
5.5.130.0010.01114.27
5.5.120.0030.00914.44
5.5.110.0060.01014.51
5.5.100.0000.01714.36
5.5.90.0050.00414.53
5.5.80.0070.00814.39
5.5.70.0040.00814.30
5.5.60.0020.01114.13
5.5.50.0090.00914.39
5.5.40.0080.00914.48
5.5.30.0050.00914.39
5.5.20.0030.01414.52
5.5.10.0080.00514.11
5.5.00.0030.00814.07
5.4.450.0260.02414.04
5.4.440.0350.02314.10
5.4.430.0320.02014.04
5.4.420.0320.02314.09
5.4.410.0260.02514.00
5.4.400.0330.02213.95
5.4.390.0340.02913.76
5.4.380.0360.02113.91
5.4.370.0370.02013.97
5.4.360.0260.02813.81
5.4.350.0260.02113.75
5.4.340.0270.02313.69
5.4.330.0020.01111.23
5.4.320.0350.02713.88
5.4.310.0290.02813.96
5.4.300.0330.02113.98
5.4.290.0360.02013.86
5.4.280.0280.02413.75
5.4.270.0270.02813.95
5.4.260.0300.02113.86
5.4.250.0270.02313.87
5.4.240.0290.02813.86
5.4.230.0260.02213.65
5.4.220.0270.02513.74
5.4.210.0290.02813.84
5.4.200.0260.02013.08
5.4.190.0240.02213.85
5.4.180.0280.02913.67
5.4.170.0240.03013.85
5.4.160.0280.02613.85
5.4.150.0200.01913.82
5.4.140.0070.02812.91
5.4.130.0080.02613.11
5.4.120.0360.02813.02
5.4.110.0330.02313.19
5.4.100.0270.02713.13
5.4.90.0280.02613.03
5.4.80.0240.02213.03
5.4.70.0260.02312.90
5.4.60.0350.01613.00
5.4.50.0270.01912.94
5.4.40.0290.02213.08
5.4.30.0320.01712.95
5.4.20.0230.02312.93
5.4.10.0250.02413.05
5.4.00.0300.02412.82
5.3.290.0770.06314.69
5.3.280.0600.07014.50
5.3.270.0800.06014.47
5.3.260.0830.05314.61
5.3.250.0730.06014.52
5.3.240.0870.05014.75
5.3.230.0730.05014.60
5.3.220.0870.05014.53
5.3.210.0900.07014.62
5.3.200.0970.05014.43
5.3.190.0100.05714.59
5.3.180.0270.03714.57
5.3.170.0470.05014.42
5.3.160.0870.04714.65
5.3.150.0770.05014.61
5.3.140.0830.07714.53
5.3.130.0770.08314.56
5.3.120.0630.06014.63
5.3.110.0770.06014.54
5.3.100.0800.05014.01
5.3.90.0770.06013.93
5.3.80.0700.06014.27
5.3.70.0670.04714.03
5.3.60.1000.04714.09
5.3.50.1130.05013.87
5.3.40.0870.04013.95
5.3.30.1000.06313.84
5.3.20.0770.05013.71
5.3.10.0730.04713.68
5.3.00.0670.05313.65
5.2.170.0830.04011.02
5.2.160.0670.04311.21
5.2.150.0670.04311.38
5.2.140.0700.04011.11
5.2.130.0570.04011.20
5.2.120.0700.04011.07
5.2.110.0700.04711.02
5.2.100.0730.04711.33
5.2.90.0730.04311.06
5.2.80.0600.05711.00
5.2.70.0730.04311.04
5.2.60.0800.05010.97
5.2.50.0670.06710.94
5.2.40.0630.03311.05
5.2.30.0530.05310.88
5.2.20.0170.03710.96
5.2.10.0030.04710.82
5.2.00.0030.04310.77
5.1.60.0100.0439.92
5.1.50.0630.0339.89
5.1.40.0500.0409.91
5.1.30.0500.04010.48
5.1.20.0600.03010.44
5.1.10.0630.0479.98
5.1.00.0630.03310.08
5.0.50.0230.0308.56
5.0.40.0300.0338.51
5.0.30.0370.0408.20
5.0.20.0370.0338.04
5.0.10.0200.0378.06
5.0.00.0330.0408.32
4.4.90.0300.0276.48
4.4.80.0300.0206.48
4.4.70.0370.0236.48
4.4.60.0370.0276.48
4.4.50.0270.0206.48
4.4.40.0300.0336.48
4.4.30.0330.0276.48
4.4.20.0300.0336.48
4.4.10.0300.0206.48
4.4.00.0300.0306.48
4.3.110.0370.0236.48
4.3.100.0370.0176.48
4.3.90.0370.0136.48
4.3.80.0330.0306.48
4.3.70.0300.0276.48
4.3.60.0300.0276.48
4.3.50.0230.0206.48
4.3.40.0170.0436.48
4.3.30.0030.0236.48
4.3.20.0070.0236.48
4.3.10.0000.0276.48
4.3.00.0100.0237.24

preferences:
58.37 ms | 401 KiB | 5 Q