3v4l.org

run code in 300+ PHP versions simultaneously
<?php $message = "This is a string using the terms? Wait here's one\nabukuma 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); var_dump($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.0140.00318.30
8.3.50.0120.00321.26
8.3.40.0100.01019.10
8.3.30.0070.00720.38
8.3.20.0040.00420.39
8.3.10.0030.00622.14
8.3.00.0060.00322.14
8.2.180.0120.00916.88
8.2.170.0090.00622.96
8.2.160.0120.00322.21
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0030.00626.16
8.2.120.0040.00420.94
8.2.110.0070.00322.42
8.2.100.0060.00617.84
8.2.90.0000.00819.22
8.2.80.0090.00019.11
8.2.70.0040.00417.75
8.2.60.0080.00017.91
8.2.50.0030.00618.07
8.2.40.0040.00419.97
8.2.30.0020.00519.47
8.2.20.0050.00317.88
8.2.10.0000.00817.91
8.2.00.0120.00017.98
8.1.270.0050.00323.99
8.1.260.0050.00326.35
8.1.250.0050.00228.09
8.1.240.0030.00623.91
8.1.230.0110.00019.07
8.1.220.0090.00017.74
8.1.210.0090.00018.77
8.1.200.0030.00717.47
8.1.190.0000.00817.53
8.1.180.0060.00319.14
8.1.170.0050.00318.87
8.1.160.0100.00018.85
8.1.150.0000.00718.80
8.1.140.0000.00717.63
8.1.130.0000.00717.83
8.1.120.0070.00017.60
8.1.110.0040.00417.52
8.1.100.0000.00817.55
8.1.90.0000.00717.65
8.1.80.0000.00717.52
8.1.70.0040.00417.53
8.1.60.0090.00017.80
8.1.50.0000.00817.73
8.1.40.0000.00817.75
8.1.30.0040.00417.84
8.1.20.0040.00417.83
8.1.10.0030.00517.78
8.1.00.0040.00417.61
8.0.300.0070.00018.77
8.0.290.0040.00417.30
8.0.280.0000.00718.39
8.0.270.0000.00717.23
8.0.260.0000.00716.98
8.0.250.0070.00017.14
8.0.240.0080.00017.11
8.0.230.0080.00017.16
8.0.220.0000.00817.05
8.0.210.0040.00416.99
8.0.200.0070.00017.18
8.0.190.0000.00816.99
8.0.180.0000.00817.04
8.0.170.0040.00417.02
8.0.160.0000.00717.09
8.0.150.0080.00016.93
8.0.140.0030.00616.93
8.0.130.0060.00013.50
8.0.120.0060.00317.04
8.0.110.0000.00717.10
8.0.100.0050.00317.07
8.0.90.0040.00417.18
8.0.80.0130.00317.04
8.0.70.0060.00317.13
8.0.60.0050.00317.01
8.0.50.0000.00716.91
8.0.30.0140.00517.22
8.0.20.0070.01217.40
8.0.10.0050.00317.16
8.0.00.0090.01017.01
7.4.330.0030.00315.02
7.4.320.0070.00016.85
7.4.300.0040.00416.74
7.4.290.0000.00816.75
7.4.280.0000.00716.80
7.4.270.0080.00016.76
7.4.260.0000.00513.62
7.4.250.0030.00516.63
7.4.240.0020.00516.66
7.4.230.0030.00316.91
7.4.220.0100.01616.74
7.4.210.0100.00716.84
7.4.200.0000.00716.56
7.4.190.0030.00517.01
7.4.160.0100.00616.82
7.4.150.0070.01117.40
7.4.140.0110.00917.86
7.4.130.0090.00816.84
7.4.120.0060.01316.72
7.4.110.0060.01216.64
7.4.100.0070.01016.79
7.4.90.0070.01016.74
7.4.80.0120.00619.39
7.4.70.0180.00416.63
7.4.60.0030.01316.79
7.4.50.0060.00316.68
7.4.40.0170.00022.77
7.4.30.0200.00016.75
7.4.00.0030.01415.15
7.3.330.0050.00013.51
7.3.320.0050.00013.53
7.3.310.0000.00716.59
7.3.300.0000.00716.54
7.3.290.0120.00316.56
7.3.280.0070.00916.50
7.3.270.0070.01017.40
7.3.260.0110.00816.66
7.3.250.0070.01216.77
7.3.240.0190.00316.60
7.3.230.0130.00616.76
7.3.210.0040.01416.90
7.3.200.0110.00819.39
7.3.190.0080.00816.54
7.3.180.0110.00416.51
7.3.170.0060.00916.77
7.3.160.0110.00616.69
7.3.120.0030.01415.06
7.3.110.0120.00514.97
7.3.100.0070.01015.08
7.3.90.0100.00615.05
7.3.80.0040.01015.23
7.3.70.0050.00815.04
7.3.60.0080.00814.95
7.3.50.0070.00515.14
7.3.40.0080.01015.11
7.3.30.0030.00814.87
7.3.20.0030.01316.81
7.3.10.0070.01016.74
7.3.00.0090.00716.78
7.2.330.0040.01416.94
7.2.320.0080.00816.82
7.2.310.0060.01216.90
7.2.300.0130.00316.80
7.2.290.0060.01016.88
7.2.250.0000.02015.37
7.2.240.0100.00815.25
7.2.230.0100.00415.32
7.2.220.0050.00915.42
7.2.210.0040.01315.16
7.2.200.0050.00515.18
7.2.190.0060.01115.22
7.2.180.0080.00915.06
7.2.170.0070.01015.08
7.2.160.0040.01115.14
7.2.150.0100.00717.00
7.2.140.0060.00617.14
7.2.130.0070.01016.97
7.2.120.0120.00317.07
7.2.110.0070.00717.30
7.2.100.0070.01017.04
7.2.90.0040.01117.21
7.2.80.0040.01417.06
7.2.70.0060.01017.42
7.2.60.0060.01117.11
7.2.50.0080.00417.27
7.2.40.0070.01017.17
7.2.30.0040.01517.00
7.2.20.0000.01517.04
7.2.10.0060.00917.16
7.2.00.0080.00518.32
7.1.330.0060.00915.81
7.1.320.0100.00416.15
7.1.310.0060.00716.04
7.1.300.0030.01315.93
7.1.290.0080.00916.03
7.1.280.0060.01015.93
7.1.270.0050.00715.89
7.1.260.0050.01116.15
7.1.250.0100.00616.14
7.1.100.0000.00818.04
7.1.70.0000.01017.39
7.1.60.0000.01417.49
7.1.50.0060.01617.27
7.1.00.0000.05722.43
7.0.200.0030.01417.13
7.0.140.0070.06722.08
7.0.70.0070.08321.68
7.0.60.0030.08321.69
7.0.50.0030.06021.97
7.0.40.0100.05320.15
7.0.30.0070.08720.13
7.0.20.0100.05320.11
7.0.10.0100.07720.02
7.0.00.0100.08020.18
5.6.220.0100.07320.69
5.6.210.0100.07720.66
5.6.200.0000.08721.04
5.6.190.0070.07321.08
5.6.180.0070.06721.07
5.6.170.0130.07321.20
5.6.160.0070.04021.05
5.6.150.0100.04721.13
5.6.140.0030.08721.15
5.6.130.0170.07321.05
5.6.120.0000.08020.97
5.6.110.0030.07720.96
5.6.100.0000.09021.09
5.6.90.0170.07721.07
5.6.80.0100.06320.36
5.6.70.0070.07320.45
5.6.60.0030.08020.33
5.6.50.0000.07320.44
5.6.40.0030.06020.49
5.6.30.0100.04720.48
5.6.20.0030.04320.39
5.6.10.0000.08020.47
5.6.00.0000.05720.33
5.5.360.0130.07320.58
5.5.350.0070.08720.39
5.5.340.0070.08020.89
5.5.330.0100.07720.80
5.5.320.0000.07020.77
5.5.310.0070.08020.77
5.5.300.0030.08320.75
5.5.290.0030.09020.89
5.5.280.0000.05320.74
5.5.270.0070.08720.79
5.5.260.0000.09320.77
5.5.250.0100.07720.64
5.5.240.0070.07720.24
5.5.230.0070.07720.20
5.5.220.0030.08720.32
5.5.210.0000.08720.25
5.5.200.0030.07720.27
5.5.190.0070.08020.17
5.5.180.0000.05020.30
5.5.160.0070.07320.14
5.5.150.0030.07720.20
5.5.140.0030.08020.27
5.5.130.0000.08020.30
5.5.120.0000.05720.29
5.5.110.0000.07020.19
5.5.100.0070.06020.12
5.5.90.0030.05320.13
5.5.80.0100.07720.03
5.5.70.0000.04020.11
5.5.60.0030.05019.95
5.5.50.0100.06020.07
5.5.40.0130.07020.07
5.5.30.0030.05320.10
5.5.20.0030.07020.16
5.5.10.0030.04719.99
5.5.00.0030.08320.06
5.4.450.0000.09019.38
5.4.440.0100.08019.21
5.4.430.0070.08019.44
5.4.420.0000.07019.35
5.4.410.0100.07319.14
5.4.400.0070.08018.88
5.4.390.0070.07319.06
5.4.380.0070.04318.89
5.4.370.0100.05719.14
5.4.360.0100.06719.09
5.4.350.0070.05019.12
5.4.340.0030.05018.90
5.4.320.0030.06319.09
5.4.310.0000.05719.03
5.4.300.0000.07719.18
5.4.290.0070.07318.85
5.4.280.0070.05019.20
5.4.270.0230.06318.94
5.4.260.0000.08319.12
5.4.250.0000.08019.05
5.4.240.0000.08319.13
5.4.230.0030.07319.02
5.4.220.0030.07319.04
5.4.210.0030.05719.02
5.4.200.0000.08319.09
5.4.190.0100.07019.04
5.4.180.0070.07719.24
5.4.170.0030.08018.86
5.4.160.0000.08319.07
5.4.150.0000.08019.10
5.4.140.0030.07316.52
5.4.130.0070.04716.51
5.4.120.0030.07716.45
5.4.110.0070.07716.54
5.4.100.0000.07316.49
5.4.90.0070.07316.33
5.4.80.0030.07316.51
5.4.70.0070.06016.55
5.4.60.0100.06716.24
5.4.50.0000.07716.26
5.4.40.0070.07316.46
5.4.30.0030.07716.46
5.4.20.0100.06716.39
5.4.10.0100.06316.39
5.4.00.0030.07015.90
5.3.290.0030.08014.64
5.3.280.0070.07314.73
5.3.270.0030.08014.57
5.3.260.0030.08014.61
5.3.250.0030.08014.60
5.3.240.0070.07314.70
5.3.230.0030.08014.56
5.3.220.0030.05314.61
5.3.210.0070.07014.56
5.3.200.0000.05314.54
5.3.190.0000.08314.65
5.3.180.0030.07714.66
5.3.170.0030.07714.66
5.3.160.0030.08014.65
5.3.150.0000.08314.68
5.3.140.0000.08314.69
5.3.130.0100.07314.64
5.3.120.0030.07714.58
5.3.110.0000.08014.64
5.3.100.0100.06714.03
5.3.90.0030.05714.00
5.3.80.0030.07714.16
5.3.70.0070.07314.20
5.3.60.0170.05014.04
5.3.50.0070.05314.00
5.3.40.0030.05714.04
5.3.30.0000.08013.86
5.3.20.0030.07713.65
5.3.10.0030.07313.68
5.3.00.0030.04313.59
5.2.170.0000.05312.30
5.2.160.0070.05012.30
5.2.150.0070.05712.30
5.2.140.0000.04312.30
5.2.130.0000.06312.30
5.2.120.0000.04312.30
5.2.110.0070.05712.30
5.2.100.0030.06012.30
5.2.90.0000.04312.30
5.2.80.0000.05312.30
5.2.70.0100.06012.30
5.2.60.0000.04312.30
5.2.50.0030.06012.30
5.2.40.0030.06312.30
5.2.30.0100.04312.30
5.2.20.0000.05312.30
5.2.10.0000.06312.30
5.2.00.0030.05712.30
5.1.60.0030.04312.30
5.1.50.0030.05712.30
5.1.40.0070.05012.30
5.1.30.0100.04712.30
5.1.20.0000.04712.30
5.1.10.0030.04712.30
5.1.00.0000.03712.30
5.0.50.0000.05012.30
5.0.40.0030.02712.30
5.0.30.0000.06712.30
5.0.20.0000.03312.30
5.0.10.0030.04712.30
5.0.00.0000.05312.30
4.4.90.0000.03712.30
4.4.80.0000.01712.30
4.4.70.0000.03012.30
4.4.60.0070.03012.30
4.4.50.0000.03712.30
4.4.40.0000.04012.30
4.4.30.0000.02712.30
4.4.20.0000.02712.30
4.4.10.0000.03312.30
4.4.00.0070.05312.30
4.3.110.0030.03312.30
4.3.100.0000.04012.30
4.3.90.0030.03312.30
4.3.80.0000.03312.30
4.3.70.0030.03312.30
4.3.60.0030.03312.30
4.3.50.0030.02712.30
4.3.40.0000.05012.30
4.3.30.0030.03312.30
4.3.20.0000.02712.30
4.3.10.0000.02712.30
4.3.00.0030.03012.30

preferences:
46.43 ms | 400 KiB | 5 Q