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 $strpos = preg_match($regexp, $haystack, $matches, PREG_OFFSET_CAPTURE, $offset); if ($strpos === false) { 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.0100.00716.72
8.3.50.0140.00521.21
8.3.40.0030.01219.10
8.3.30.0070.01020.31
8.3.20.0070.00720.29
8.3.10.0030.00622.15
8.3.00.0080.00022.43
8.2.180.0120.00618.66
8.2.170.0150.00622.96
8.2.160.0140.00022.25
8.2.150.0060.01324.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0050.00320.88
8.2.110.0060.00320.52
8.2.100.0070.00417.91
8.2.90.0000.00819.17
8.2.80.0000.00819.34
8.2.70.0040.00417.75
8.2.60.0000.00817.93
8.2.50.0000.00818.07
8.2.40.0080.00020.07
8.2.30.0000.00819.35
8.2.20.0030.00617.90
8.2.10.0030.00618.00
8.2.00.0000.00917.99
8.1.280.0090.00625.92
8.1.270.0080.00023.99
8.1.260.0050.00326.35
8.1.250.0000.00728.09
8.1.240.0060.00323.81
8.1.230.0030.00819.00
8.1.220.0040.00417.80
8.1.210.0000.00818.77
8.1.200.0030.00617.50
8.1.190.0000.00817.63
8.1.180.0050.00319.12
8.1.170.0040.00418.84
8.1.160.0040.00418.94
8.1.150.0000.00818.72
8.1.140.0000.01017.57
8.1.130.0070.00017.87
8.1.120.0050.00217.54
8.1.110.0000.00717.63
8.1.100.0040.00417.49
8.1.90.0040.00417.65
8.1.80.0040.00417.54
8.1.70.0000.00717.59
8.1.60.0060.00317.62
8.1.50.0030.00517.62
8.1.40.0000.00817.61
8.1.30.0090.00017.84
8.1.20.0090.00017.77
8.1.10.0020.00517.75
8.1.00.0050.00317.61
8.0.300.0050.00218.77
8.0.290.0040.00417.43
8.0.280.0000.00718.50
8.0.270.0040.00417.23
8.0.260.0040.00416.91
8.0.250.0070.00017.10
8.0.240.0060.00317.10
8.0.230.0040.00417.15
8.0.220.0000.00717.06
8.0.210.0000.00716.97
8.0.200.0040.00417.16
8.0.190.0040.00417.05
8.0.180.0000.00717.08
8.0.170.0030.00617.01
8.0.160.0040.00417.07
8.0.150.0020.00516.96
8.0.140.0080.00317.01
8.0.130.0030.00313.45
8.0.120.0040.00417.05
8.0.110.0030.00516.89
8.0.100.0040.00417.10
8.0.90.0050.00316.90
8.0.80.0100.00616.98
8.0.70.0000.00717.02
8.0.60.0000.00716.91
8.0.50.0000.00817.09
8.0.30.0130.00917.46
8.0.20.0100.01017.40
8.0.10.0030.00517.09
8.0.00.0120.00616.93
7.4.330.0000.00515.00
7.4.320.0030.00316.76
7.4.300.0060.00016.73
7.4.290.0070.00016.86
7.4.280.0000.00716.74
7.4.270.0030.00316.69
7.4.260.0000.00513.47
7.4.250.0020.00516.79
7.4.240.0070.00016.86
7.4.230.0000.00716.77
7.4.220.0190.00016.81
7.4.210.0100.00416.90
7.4.200.0000.00716.74
7.4.190.0040.00416.91
7.4.160.0060.01216.82
7.4.150.0180.00017.40
7.4.140.0110.01017.86
7.4.130.0090.00916.82
7.4.120.0110.00616.87
7.4.110.0150.00316.77
7.4.100.0130.00416.86
7.4.90.0040.01416.75
7.4.80.0060.01819.39
7.4.70.0180.00016.82
7.4.60.0090.00916.75
7.4.50.0050.00316.47
7.4.40.0090.00522.77
7.4.30.0070.01316.74
7.4.00.0060.01015.20
7.3.330.0050.00013.35
7.3.320.0000.00513.56
7.3.310.0000.00816.54
7.3.300.0050.00216.37
7.3.290.0030.01016.51
7.3.280.0070.01216.58
7.3.270.0090.00917.40
7.3.260.0100.01416.81
7.3.250.0070.01016.61
7.3.240.0090.00916.89
7.3.230.0130.00616.81
7.3.210.0070.01016.42
7.3.200.0090.00919.39
7.3.190.0100.01016.69
7.3.180.0130.00316.76
7.3.170.0060.00916.78
7.3.160.0120.00616.55
7.3.120.0090.00615.24
7.2.330.0140.00416.97
7.2.320.0090.00916.99
7.2.310.0090.01516.91
7.2.300.0090.00916.74
7.2.290.0110.00616.75
7.2.80.0130.00316.67
7.2.60.0160.00016.80
7.2.00.0030.01019.77
7.1.200.0070.00015.98
7.1.70.0040.00417.46
7.1.60.0090.00617.40
7.1.50.0070.01316.98
7.1.00.0000.03722.50
7.0.200.0030.01316.95
7.0.140.0130.06322.08
7.0.60.0100.08319.96
7.0.50.0030.04317.83
7.0.40.0030.08720.20
7.0.30.0300.05320.31
7.0.20.0370.06320.23
7.0.10.0170.08320.21
7.0.00.0100.05320.12
5.6.280.0100.06721.13
5.6.210.0130.08020.56
5.6.200.0130.03318.18
5.6.190.0000.09320.48
5.6.180.0270.07320.50
5.6.170.0270.03020.54
5.6.160.0100.06720.48
5.6.150.0030.04318.14
5.6.140.0070.08018.28
5.6.130.0030.04018.28
5.6.120.0130.06320.99
5.6.110.0070.06321.03
5.6.100.0170.07321.16
5.6.90.0030.08020.90
5.6.80.0100.07020.43
5.5.350.4230.04020.31
5.5.340.0130.07317.96
5.5.330.0070.07020.57
5.5.320.0300.03320.28
5.5.310.0230.04320.21
5.5.300.0130.07317.97
5.5.290.0130.07717.93
5.5.280.0070.08020.90
5.5.270.0000.04320.69
5.5.260.0030.07320.78
5.5.250.0170.07320.70
5.5.240.0370.07020.05
5.4.450.0400.04019.41
5.4.440.0330.04319.56
5.4.430.0530.06019.42
5.4.420.0370.03719.43
5.4.410.0300.03719.17
5.4.400.0400.06319.00
5.4.390.0300.04718.86
5.4.380.0400.07019.17
5.4.370.0400.03019.31
5.4.360.0330.04018.95
5.4.350.0500.06019.25
5.4.340.0370.04319.00
5.4.320.0330.04019.01
5.4.310.0370.04018.86
5.4.300.0370.06019.11
5.4.290.0530.06019.16
5.4.280.0370.04719.31
5.4.270.0400.06719.16
5.4.260.0530.05719.16
5.4.250.0330.03319.22
5.4.240.0430.07018.97
5.4.230.0300.04718.97
5.4.220.0300.03719.11
5.4.210.0300.03719.11
5.4.200.0330.03319.30
5.4.190.0300.03019.21
5.4.180.0230.04019.21
5.4.170.0300.04319.13
5.4.160.0200.04019.14
5.4.150.0230.04319.09
5.4.140.0300.03016.56
5.4.130.0270.03316.36
5.4.120.0330.03716.37
5.4.110.0270.03316.50
5.4.100.0330.03316.25
5.4.90.0300.03016.62
5.4.80.0170.04016.55
5.4.70.0230.03316.59
5.4.60.0270.03716.44
5.4.50.0300.03016.35
5.4.40.0230.04316.49
5.4.30.0270.03716.54
5.4.20.0230.03316.54
5.4.10.0070.04016.44
5.4.00.0030.03715.81
5.3.290.0100.04314.61
5.3.280.0200.03714.61
5.3.270.0300.03714.59
5.3.260.0270.04014.72
5.3.250.0200.04014.54
5.3.240.0200.04314.64
5.3.230.0270.04314.71
5.3.220.0270.03714.67
5.3.210.0270.04314.60
5.3.200.0230.03714.59
5.3.190.0270.03714.68
5.3.180.0200.04014.72
5.3.170.0300.03714.68
5.3.160.0270.03714.50
5.3.150.0370.04014.57
5.3.140.0400.02714.49
5.3.130.0270.03714.72
5.3.120.0300.03314.66
5.3.110.0270.03314.50
5.3.100.0230.03714.05
5.3.90.0230.04314.16
5.3.80.0230.03713.95
5.3.70.0300.03014.13
5.3.60.0230.04013.95
5.3.50.0270.03717.00
5.3.40.0230.04317.09
5.3.30.0300.03716.97
5.3.20.0300.03316.81
5.3.10.0200.04016.64
5.3.00.0270.03716.81
5.2.170.0230.03012.65
5.2.160.0230.02712.65
5.2.150.0200.03312.65
5.2.140.0230.03012.65
5.2.130.0170.03012.65
5.2.120.0170.03012.65
5.2.110.0170.03012.65
5.2.100.0170.03012.65
5.2.90.0230.02712.65
5.2.80.0230.02312.65
5.2.70.0230.04012.65
5.2.60.0270.03712.65
5.2.50.0230.03312.65
5.2.40.0130.03012.65
5.2.30.0230.02712.65
5.2.20.0300.06012.65
5.2.10.0170.04712.65
5.2.00.0170.03712.65
5.1.60.0170.02312.65
5.1.50.0200.02312.65
5.1.40.0230.04712.65
5.1.30.0300.02712.65
5.1.20.0330.05012.65
5.1.10.0230.02312.65
5.1.00.0230.04312.65
5.0.50.0130.04712.65
5.0.40.0100.02712.65
5.0.30.0100.03012.65
5.0.20.0170.03012.65
5.0.10.0170.02012.65
5.0.00.0170.03712.65
4.4.90.0130.03712.65
4.4.80.0130.01312.65
4.4.70.0100.01712.65
4.4.60.0130.01712.65
4.4.50.0130.03312.65
4.4.40.0100.02712.65
4.4.30.0130.02012.65
4.4.20.0170.01712.65
4.4.10.0100.02012.65
4.4.00.0170.05012.65
4.3.110.0130.01712.65
4.3.100.0170.03012.65
4.3.90.0170.02312.65
4.3.80.0130.02712.65
4.3.70.0100.02312.65
4.3.60.0130.02312.65
4.3.50.0130.03312.65
4.3.40.0070.02712.65
4.3.30.0070.03712.65
4.3.20.0030.02012.65
4.3.10.0070.03012.65
4.3.00.0070.02712.65

preferences:
45.74 ms | 401 KiB | 5 Q