3v4l.org

run code in 300+ PHP versions simultaneously
<?php $message = "This is a string using the terms? Wait here's one\n abukuma kai\nabukuma-kai\nabukuma\nabukuma\nkai abukuma abukuma kai"; $search = array( 'abukuma kai', 'abukuma' ); $replacements = array( '<a href="http://kancolle.wikia.com/wiki/Abukuma#Upgrade" class="screenshot" rel="ship/Abukuma_Kai.png" style="color:#0073e6; font-weight:bold; border-bottom: 1px #0073e6 dashed;"><p id="yosup">Abukuma Kai</p></a>', '<a href="http://kancolle.wikia.com/wiki/Abukuma#Basic" class="screenshot" rel="ship/Abukuma.png" style="color:#0073e6; font-weight:bold; border-bottom: 1px #0073e6 dashed;">Abukuma</a>' ); function replaceStrings($haystack, $needle, $replacement, $offset = 0) { if (count($needle) != count($replacement)) { throw new \InvalidArgumentException('Needle length must match replacement length'); } $regexpDelimiter = '/'; $wordDelimiter = '[-\s_]'; // Create the regexp if (is_array($needle)) { $massagedNeedles = array_map( function($s) use($regexpDelimiter, $wordDelimiter) { $s = preg_quote($s, $regexpDelimiter); $s = str_replace(' ', $wordDelimiter, $s); return $s; }, $needle ); // Sort it reverse so we get the longer strings first usort($massagedNeedles, function($a, $b) { return strlen($b) - strlen($a); }); $regexp = implode('|', $massagedNeedles); } else { $regexp = str_replace(' ', $wordDelimiter, preg_quote($needle, $regexpDelimiter)); } $regexp = sprintf('%1$s%2$s%1$si', $regexpDelimiter, $regexp); // Now find the next occurence if (!preg_match($regexp, $haystack, $matches, PREG_OFFSET_CAPTURE, $offset)) { return $haystack; } $found = array_search(preg_replace('/' . $wordDelimiter . '/', ' ', $matches[0][0]), $needle); $haystack = substr_replace($haystack, $replacement[$found], $matches[0][1], strlen($matches[0][0])); return replaceStrings($haystack, $needle, $replacement, $offset + $matches[0][1] + strlen($replacement[$found])); } var_dump(replaceStrings($message, $search, $replacements));

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.0090.00616.50
8.3.50.0100.00817.51
8.3.40.0110.00419.04
8.3.30.0070.00718.79
8.3.20.0040.00418.89
8.3.10.0080.00019.07
8.3.00.0040.00419.38
8.2.180.0140.00318.41
8.2.170.0130.00719.21
8.2.160.0080.00522.96
8.2.150.0000.00825.66
8.2.140.0030.00624.66
8.2.130.0040.00426.16
8.2.120.0040.00420.88
8.2.110.0060.00321.18
8.2.100.0040.00817.91
8.2.90.0070.00419.48
8.2.80.0040.00419.25
8.2.70.0000.00817.75
8.2.60.0050.00317.93
8.2.50.0080.00018.07
8.2.40.0040.00418.28
8.2.30.0040.00418.06
8.2.20.0000.01017.92
8.2.10.0040.00417.99
8.2.00.0000.00718.04
8.1.280.0070.00725.92
8.1.270.0030.00524.66
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00622.66
8.1.230.0060.00620.95
8.1.220.0090.00017.74
8.1.210.0030.00618.96
8.1.200.0030.00617.48
8.1.190.0060.00317.66
8.1.180.0060.00318.10
8.1.170.0040.00418.87
8.1.160.0000.00718.98
8.1.150.0030.00618.86
8.1.140.0000.00817.66
8.1.130.0030.00317.94
8.1.120.0040.00417.65
8.1.110.0050.00317.56
8.1.100.0040.00417.52
8.1.90.0040.00417.59
8.1.80.0000.00717.52
8.1.70.0000.00717.61
8.1.60.0000.00817.79
8.1.50.0090.00017.63
8.1.40.0030.00617.66
8.1.30.0000.00817.82
8.1.20.0040.00417.70
8.1.10.0040.00417.64
8.1.00.0030.00617.65
8.0.300.0030.00620.01
8.0.290.0070.00016.73
8.0.280.0070.00018.55
8.0.270.0030.00317.18
8.0.260.0030.00317.00
8.0.250.0000.00817.13
8.0.240.0040.00417.13
8.0.230.0040.00417.12
8.0.220.0030.00316.96
8.0.210.0030.00317.07
8.0.200.0000.00717.11
8.0.190.0040.00317.16
8.0.180.0000.00817.06
8.0.170.0060.00317.05
8.0.160.0000.00717.02
8.0.150.0040.00417.03
8.0.140.0070.00016.94
8.0.130.0060.00013.45
8.0.120.0090.00017.02
8.0.110.0000.00816.96
8.0.100.0050.00317.06
8.0.90.0000.00716.86
8.0.80.0120.00317.11
8.0.70.0040.00416.91
8.0.60.0040.00417.08
8.0.50.0070.00017.09
8.0.30.0070.01417.43
8.0.20.0080.01217.24
8.0.10.0000.00717.21
8.0.00.0150.00817.09
7.4.330.0000.00513.21
7.4.320.0030.00316.68
7.4.300.0040.00416.74
7.4.290.0000.00716.77
7.4.280.0060.00316.84
7.4.270.0050.00316.80
7.4.260.0050.00013.47
7.4.250.0030.00616.72
7.4.240.0050.00216.73
7.4.230.0000.00716.91
7.4.220.0060.01216.84
7.4.210.0080.00716.88
7.4.200.0030.00316.82
7.4.190.0000.00716.92
7.4.160.0130.00316.75
7.4.150.0140.00416.87
7.4.140.0110.00616.84
7.4.130.0060.01016.69
7.4.120.0120.00716.69
7.4.110.0060.01516.64
7.4.100.0100.00716.97
7.4.90.0070.01116.77
7.4.80.0100.01316.66
7.4.70.0060.01216.70
7.4.60.0160.00016.78
7.4.50.0050.00516.61
7.4.40.0080.00416.58
7.4.30.0100.01016.81
7.4.00.0030.01015.12
7.3.330.0070.00013.61
7.3.320.0000.00513.54
7.3.310.0000.00716.43
7.3.300.0000.00716.59
7.3.290.0000.01416.46
7.3.280.0080.00716.51
7.3.270.0180.00316.67
7.3.260.0070.01116.57
7.3.250.0110.00716.66
7.3.240.0100.00716.82
7.3.230.0110.00716.82
7.3.210.0100.00616.73
7.3.200.0090.01219.39
7.3.190.0030.01316.48
7.3.180.0090.00616.78
7.3.170.0120.00416.91
7.3.160.0080.00816.60
7.3.120.0040.01415.29
7.2.330.0120.01216.99
7.2.320.0090.00916.83
7.2.310.0190.02316.94
7.2.300.0080.00816.89
7.2.290.0110.00616.74
7.2.00.0070.01019.60
7.1.200.0070.00715.70
7.1.100.0160.00718.38
7.1.70.0000.01017.22
7.1.60.0100.01419.40
7.1.50.0060.01517.30
7.1.00.0130.06022.46
7.0.200.0130.00915.08
7.0.140.0030.07722.17
7.0.120.0030.07322.16
7.0.60.0030.04319.92
7.0.50.0100.03317.89
7.0.40.0030.04017.87
7.0.30.0030.04017.73
7.0.20.0070.03717.77
7.0.10.0030.04017.82
7.0.00.0030.06717.74
5.6.210.0100.07720.68
5.6.200.0000.04318.28
5.6.190.0000.04318.28
5.6.180.0000.04018.18
5.6.170.0000.04318.14
5.6.160.0030.03718.19
5.6.150.0030.04018.14
5.6.140.0000.04018.25
5.6.130.0030.04018.15
5.6.120.0030.04018.17
5.6.110.0000.04318.18
5.6.100.0070.03718.20
5.6.90.0030.04318.17
5.6.80.0000.04017.56
5.6.70.0000.04017.63
5.6.60.0070.06317.53
5.6.50.0030.04017.54
5.6.40.0000.08317.51
5.6.30.0100.07717.55
5.6.20.0130.06317.63
5.6.10.0100.04017.49
5.6.00.0170.07317.52
5.5.350.0330.07320.43
5.5.340.0000.04018.05
5.5.330.0030.03717.98
5.5.320.0000.04017.99
5.5.310.0030.04017.98
5.5.300.0130.02718.01
5.5.290.0100.03718.02
5.5.280.0070.04317.95
5.5.270.0000.04717.93
5.5.260.0030.04018.01
5.5.250.0100.03717.86
5.5.240.0000.04017.36
5.5.230.0030.03717.36
5.5.220.0030.04717.37
5.5.210.0100.07317.36
5.5.200.0070.04317.39
5.5.190.0000.05717.40
5.5.180.0000.08017.40
5.5.160.0100.04717.39
5.5.150.0070.05317.32
5.5.140.0030.08317.33
5.5.130.0070.04717.43
5.5.120.0070.07717.40
5.5.110.0030.04017.34
5.5.100.0130.03017.23
5.5.90.0100.05717.35
5.5.80.0130.06717.27
5.5.70.0200.04717.31
5.5.60.0100.07017.29
5.5.50.0030.05017.23
5.5.40.0070.04317.22
5.5.30.0170.06717.22
5.5.20.0000.06317.20
5.5.10.0100.07717.21
5.5.00.0130.06717.18
5.4.450.0030.04319.39
5.4.440.0030.04019.39
5.4.430.0000.04019.63
5.4.420.0100.03019.30
5.4.410.0030.03719.24
5.4.400.0000.04019.02
5.4.390.0030.03719.07
5.4.380.0070.05019.02
5.4.370.0000.04319.02
5.4.360.0000.08019.10
5.4.350.0000.05019.10
5.4.340.0070.05718.98
5.4.320.0130.07019.05
5.4.310.0130.07018.95
5.4.300.0070.07019.02
5.4.290.0130.04719.05
5.4.280.0130.07318.98
5.4.270.0030.05019.27
5.4.260.0030.05019.12
5.4.250.0070.03719.31
5.4.240.0170.05019.01
5.4.230.0030.07019.09
5.4.220.0030.05319.11
5.4.210.0000.07019.13
5.4.200.0030.06019.04
5.4.190.0100.07319.04
5.4.180.0000.05318.87
5.4.170.0030.04319.12
5.4.160.0100.04719.07
5.4.150.0030.04718.93
5.4.140.0130.06716.44
5.4.130.0000.07716.44
5.4.120.0130.06316.34
5.4.110.0100.05016.47
5.4.100.0070.03716.54
5.4.90.0000.04716.52
5.4.80.0000.04316.34
5.4.70.0070.04316.44
5.4.60.0000.04316.52
5.4.50.0070.07316.23
5.4.40.0070.07016.40
5.4.30.0030.06016.39
5.4.20.0070.03316.39
5.4.10.0070.07316.40
5.4.00.0100.06315.80
5.3.290.0000.05314.54
5.3.280.0100.04714.68
5.3.270.0100.05014.63
5.3.260.0100.03314.65
5.3.250.0030.05014.68
5.3.240.0100.07714.70
5.3.230.0130.05014.61
5.3.220.0100.05314.55
5.3.210.0030.04714.56
5.3.200.0070.07014.81
5.3.190.0070.08014.70
5.3.180.0070.07714.60
5.3.170.0100.06314.69
5.3.160.0000.08014.69
5.3.150.0070.03314.57
5.3.140.0170.07014.64
5.3.130.0030.04014.61
5.3.120.0070.03714.54
5.3.110.0030.04014.61
5.3.100.0130.07014.03
5.3.90.0030.07014.05
5.3.80.0200.05713.89
5.3.70.0030.07314.07
5.3.60.0100.07014.23
5.3.50.0130.06714.18
5.3.40.0100.07013.82
5.3.30.0070.06314.14
5.3.20.0070.04313.73
5.3.10.0070.07313.69
5.3.00.0030.06713.87
5.2.170.0070.04011.15
5.2.160.0030.06711.22
5.2.150.0030.03711.19
5.2.140.0070.06711.13
5.2.130.0070.02710.95
5.2.120.0030.06711.14
5.2.110.0070.06011.10
5.2.100.0170.03711.10
5.2.90.0000.06311.09
5.2.80.0030.05311.20
5.2.70.0100.06011.14
5.2.60.0070.03011.09
5.2.50.0030.04311.23
5.2.40.0000.03711.07
5.2.30.0030.04011.04
5.2.20.0000.03311.17
5.2.10.0070.05710.94
5.2.00.0070.06010.76
5.1.60.0000.03310.22
5.1.50.0070.03710.06
5.1.40.0030.03710.03
5.1.30.0100.05310.23
5.1.20.0070.03710.39
5.1.10.0030.0609.90
5.1.00.0070.05310.07
5.0.50.0070.0278.55
5.0.40.0070.0438.39
5.0.30.0100.0578.21
5.0.20.0030.0308.03
5.0.10.0030.0378.21
5.0.00.0130.0438.10
4.4.90.0130.0208.00
4.4.80.0070.0338.00
4.4.70.0000.0278.00
4.4.60.0000.0338.00
4.4.50.0070.0208.00
4.4.40.0000.0538.00
4.4.30.0030.0238.00
4.4.20.0070.0178.00
4.4.10.0000.0338.00
4.4.00.0000.0408.00
4.3.110.0000.0178.00
4.3.100.0030.0378.00
4.3.90.0030.0338.00
4.3.80.0030.0238.00
4.3.70.0100.0308.00
4.3.60.0030.0308.00
4.3.50.0100.0278.00
4.3.40.0000.0578.00
4.3.30.0030.0338.00
4.3.20.0030.0278.00
4.3.10.0030.0278.00
4.3.00.0030.0378.00

preferences:
41.45 ms | 401 KiB | 5 Q