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 = '[- \t_]'; // 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 using the regex we created if (!preg_match($regexp, $haystack, $matches, PREG_OFFSET_CAPTURE, $offset)) { // We've not found one. Let's say we're done. return $haystack; } // We've found one. Clean it up so we can find what replacement it uses $found = array_search(preg_replace('/' . $wordDelimiter . '/', ' ', $matches[0][0]), $needle); if ($found !== false) { $haystack = substr_replace($haystack, $replacement[$found], $matches[0][1], strlen($matches[0][0])); $offset = $matches[0][1] + strlen($replacement[$found]); } else { // This.. shouldn't happen but maybe it will. Let's code a bit defensively. $offset = $matches[0][1] + strlen($matches[0][0]); } return replaceStrings($haystack, $needle, $replacement, $offset); } 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.0060.01016.88
8.3.50.0100.00717.28
8.3.40.0120.00418.95
8.3.30.0000.01519.04
8.3.20.0080.00018.88
8.3.10.0050.00318.98
8.3.00.0030.00519.38
8.2.180.0040.01117.00
8.2.170.0120.00322.96
8.2.160.0100.00320.35
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0000.00821.00
8.2.110.0070.00319.34
8.2.100.0110.00018.03
8.2.90.0000.00819.42
8.2.80.0040.00419.38
8.2.70.0000.00917.88
8.2.60.0080.00018.05
8.2.50.0040.00418.07
8.2.40.0040.00418.03
8.2.30.0000.00818.23
8.2.20.0060.00317.97
8.2.10.0040.00417.91
8.2.00.0030.00518.02
8.1.280.0140.00025.92
8.1.270.0030.00624.66
8.1.260.0040.00426.35
8.1.250.0030.00628.09
8.1.240.0090.00022.57
8.1.230.0080.00321.15
8.1.220.0000.00817.78
8.1.210.0040.00419.08
8.1.200.0070.00317.72
8.1.190.0000.00817.66
8.1.180.0030.00618.10
8.1.170.0040.00418.87
8.1.160.0080.00018.96
8.1.150.0080.00018.90
8.1.140.0030.00517.59
8.1.130.0030.00317.90
8.1.120.0030.00517.55
8.1.110.0000.00817.66
8.1.100.0040.00417.69
8.1.90.0000.00717.64
8.1.80.0070.00017.69
8.1.70.0030.00317.54
8.1.60.0040.00417.77
8.1.50.0030.00617.67
8.1.40.0030.00617.67
8.1.30.0000.00817.74
8.1.20.0080.00017.78
8.1.10.0000.00817.73
8.1.00.0060.00317.71
8.0.300.0030.00520.11
8.0.290.0040.00416.88
8.0.280.0000.00718.46
8.0.270.0040.00417.32
8.0.260.0030.00317.07
8.0.250.0050.00316.98
8.0.240.0030.00317.14
8.0.230.0000.00717.07
8.0.220.0030.00317.06
8.0.210.0000.00717.10
8.0.200.0000.00717.11
8.0.190.0040.00417.05
8.0.180.0070.00017.00
8.0.170.0040.00417.09
8.0.160.0000.00717.02
8.0.150.0030.00617.03
8.0.140.0000.00816.90
8.0.130.0030.00313.54
8.0.120.0000.00817.08
8.0.110.0040.00416.96
8.0.100.0000.00717.15
8.0.90.0040.00416.91
8.0.80.0100.00617.00
8.0.70.0030.00617.04
8.0.60.0040.00416.88
8.0.50.0040.00417.07
8.0.30.0120.01217.49
8.0.20.0150.00617.31
8.0.10.0080.00017.03
8.0.00.0160.01216.92
7.4.330.0020.00213.30
7.4.320.0030.00316.75
7.4.300.0000.00716.66
7.4.290.0050.00316.84
7.4.280.0030.00616.86
7.4.270.0040.00416.77
7.4.260.0030.00313.57
7.4.250.0000.00816.70
7.4.240.0020.00616.87
7.4.230.0050.00216.57
7.4.220.0110.00716.86
7.4.210.0090.00916.86
7.4.200.0000.00716.56
7.4.190.0040.00416.71
7.4.160.0100.00616.73
7.4.150.0090.00916.94
7.4.140.0090.00916.71
7.4.130.0100.01116.81
7.4.120.0120.00516.86
7.4.110.0070.01016.82
7.4.100.0090.00916.71
7.4.90.0090.00916.72
7.4.80.0130.00416.72
7.4.70.0120.00616.66
7.4.60.0100.00716.74
7.4.50.0140.00016.59
7.4.40.0030.01416.67
7.4.30.0060.01016.75
7.4.10.0090.00915.23
7.4.00.0030.01315.24
7.3.330.0000.00613.37
7.3.320.0060.00013.53
7.3.310.0040.00416.39
7.3.300.0070.00016.58
7.3.290.0090.00616.58
7.3.280.0070.01116.54
7.3.270.0120.00616.49
7.3.260.0100.01316.50
7.3.250.0110.01316.82
7.3.240.0130.00316.77
7.3.230.0040.01316.84
7.3.210.0140.00416.64
7.3.200.0100.01319.39
7.3.190.0100.00716.56
7.3.180.0130.00416.80
7.3.170.0070.01016.57
7.3.160.0140.00816.63
7.3.130.0070.01115.08
7.3.120.0070.00915.08
7.3.110.0040.01414.88
7.3.100.0070.00714.94
7.3.90.0000.01415.02
7.3.80.0030.00615.02
7.3.70.0040.01414.88
7.3.60.0070.00715.08
7.3.50.0030.00615.18
7.3.40.0060.00914.97
7.3.30.0030.00615.13
7.3.20.0060.00616.69
7.3.10.0060.00616.71
7.3.00.0030.00616.78
7.2.330.0100.01316.75
7.2.320.0060.01217.11
7.2.310.0050.02217.04
7.2.300.0100.00716.80
7.2.290.0070.01016.88
7.2.260.0100.01015.20
7.2.250.0030.01415.43
7.2.240.0040.01115.38
7.2.230.0060.01015.26
7.2.220.0070.01015.44
7.2.210.0030.00815.44
7.2.200.0030.01415.11
7.2.190.0030.00715.28
7.2.180.0050.00515.38
7.2.170.0060.01315.32
7.2.160.0000.01315.35
7.2.150.0000.01217.10
7.2.140.0090.00617.19
7.2.130.0100.00717.16
7.2.120.0090.00017.03
7.2.110.0030.00917.22
7.2.100.0030.00616.97
7.2.90.0030.00917.09
7.2.80.0120.00417.25
7.2.70.0060.00917.33
7.2.60.0090.00416.97
7.2.50.0060.00917.16
7.2.40.0030.01017.27
7.2.30.0000.01317.01
7.2.20.0000.01317.29
7.2.10.0060.00617.15
7.2.00.0030.01218.45
7.1.330.0090.00616.07
7.1.320.0050.00516.00
7.1.310.0090.00615.86
7.1.300.0060.00615.84
7.1.290.0000.01416.24
7.1.280.0000.01215.79
7.1.270.0090.00616.10
7.1.260.0090.00616.03
7.1.250.0070.01016.07
7.1.240.0040.00816.11
7.1.230.0110.00016.02
7.1.220.0000.00816.02
7.1.210.0090.00615.71
7.1.200.0070.00316.11
7.1.190.0070.00716.02
7.1.180.0070.00415.79
7.1.170.0070.00315.98
7.1.160.0070.00715.66
7.1.150.0080.00815.92
7.1.140.0040.00716.04
7.1.130.0060.00616.07
7.1.120.0110.00415.86
7.1.110.0040.01116.18
7.1.100.0110.00816.98
7.1.90.0090.00615.94
7.1.80.0070.00716.11
7.1.70.0060.00616.70
7.1.60.0030.00816.82
7.1.50.0130.00316.57
7.1.40.0030.01016.20
7.1.30.0030.00915.76
7.1.20.0000.01016.10
7.1.10.0070.01115.90
7.1.00.0060.03919.21
7.0.330.0150.00315.58
7.0.320.0030.00615.48
7.0.310.0050.00515.51
7.0.300.0030.00915.40
7.0.290.0040.00815.49
7.0.280.0000.00915.36
7.0.270.0030.00915.65
7.0.260.0030.00615.68
7.0.250.0030.00915.57
7.0.240.0050.00515.73
7.0.230.0030.01215.55
7.0.220.0070.00715.65
7.0.210.0070.00315.44
7.0.200.0090.00516.36
7.0.190.0070.00715.75
7.0.180.0030.00915.58
7.0.170.0000.00815.73
7.0.160.0040.01115.64
7.0.150.0000.01215.64
7.0.140.0030.04118.81
7.0.130.0040.00415.74
7.0.120.0080.02718.84
7.0.110.0070.01015.74
7.0.100.0000.00815.76
7.0.90.0000.01115.53
7.0.80.0030.01015.44
7.0.70.0070.00315.82
7.0.60.0020.04417.78
7.0.50.0050.03316.96
7.0.40.0100.04316.90
7.0.30.0130.04816.91
7.0.20.0080.02717.02
7.0.10.0210.03316.85
7.0.00.0080.03517.02
5.6.400.0040.00914.70
5.6.390.0110.00414.77
5.6.380.0060.00614.72
5.6.370.0080.00314.66
5.6.360.0030.01014.22
5.6.350.0000.01114.09
5.6.340.0030.01014.81
5.6.330.0110.00314.50
5.6.320.0040.01214.60
5.6.310.0070.01014.67
5.6.300.0060.00914.35
5.6.290.0080.00614.46
5.6.280.0070.00714.58
5.6.270.0100.00014.64
5.6.260.0030.00814.56
5.6.250.0050.00514.49
5.6.240.0000.01414.27
5.6.230.0000.01314.34
5.6.220.0060.00914.19
5.6.210.0080.04117.40
5.6.200.0100.04316.35
5.6.190.0050.02817.69
5.6.180.0100.02517.46
5.6.170.0160.04717.53
5.6.160.0080.04817.34
5.6.150.0040.04916.50
5.6.140.0040.03116.35
5.6.130.0050.02916.49
5.6.120.0110.02217.79
5.6.110.0030.04817.80
5.6.100.0080.04217.71
5.6.90.0080.04517.76
5.6.80.0050.04917.49
5.6.70.0140.04417.40
5.6.60.0050.00514.18
5.6.50.0060.00314.49
5.6.40.0030.01014.52
5.6.30.0080.00414.18
5.6.20.0000.00914.34
5.6.10.0030.00614.53
5.6.00.0070.00714.30
5.5.380.0120.00314.32
5.5.370.0070.01114.06
5.5.360.0000.01614.50
5.5.350.0220.03717.44
5.5.340.0070.04516.15
5.5.330.0050.02717.32
5.5.320.0130.04017.61
5.5.310.0180.03817.42
5.5.300.0120.01716.06
5.5.290.0070.04516.06
5.5.280.0080.04417.71
5.5.270.0120.04417.42
5.5.260.0040.02417.51
5.5.250.0070.04317.66
5.5.240.0090.03217.33
5.5.230.0060.00914.16
5.5.220.0120.00314.27
5.5.210.0030.00614.14
5.5.200.0060.00914.22
5.5.190.0000.01314.29
5.5.180.0040.01214.26
5.5.170.0080.00814.61
5.5.160.0070.00714.30
5.5.150.0030.01214.48
5.5.140.0030.01214.09
5.5.130.0030.01014.18
5.5.120.0040.01114.47
5.5.110.0080.00414.40
5.5.100.0070.00714.22
5.5.90.0030.01414.46
5.5.80.0040.01214.27
5.5.70.0040.01114.41
5.5.60.0030.01314.39
5.5.50.0070.00314.42
5.5.40.0070.00714.41
5.5.30.0100.00614.13
5.5.20.0070.01114.33
5.5.10.0040.01214.67
5.5.00.0060.00313.96
5.4.450.0030.04815.34
5.4.440.0030.03115.31
5.4.430.0080.03615.35
5.4.420.0080.03715.25
5.4.410.0070.02715.23
5.4.400.0080.04015.20
5.4.390.0060.04015.12
5.4.380.0020.03114.98
5.4.370.0030.04115.07
5.4.360.0040.02915.27
5.4.350.0070.03815.21
5.4.340.0090.02315.29
5.4.330.0110.00011.35
5.4.320.0100.01715.22
5.4.310.0070.03315.18
5.4.300.0070.04215.21
5.4.290.0050.02715.20
5.4.280.0090.03915.20
5.4.270.0070.04315.31
5.4.260.0030.02315.25
5.4.250.0090.01815.02
5.4.240.0070.02315.15
5.4.230.0050.03114.95
5.4.220.0130.03315.03
5.4.210.0070.02515.16
5.4.200.0050.03815.08
5.4.190.0020.02215.05
5.4.180.0030.02315.18
5.4.170.0040.04415.22
5.4.160.0070.04015.06
5.4.150.0080.03114.98
5.4.140.0070.04013.77
5.4.130.0070.03713.60
5.4.120.0080.03613.83
5.4.110.0020.02813.70
5.4.100.0050.04113.87
5.4.90.0030.04213.74
5.4.80.0040.04013.97
5.4.70.0040.03113.90
5.4.60.0080.02513.71
5.4.50.0050.02213.81
5.4.40.0080.03813.86
5.4.30.0080.03313.85
5.4.20.0030.04113.91
5.4.10.0050.02513.84
5.4.00.0060.04113.36
5.3.290.0030.04512.79
5.3.280.0050.04212.69
5.3.270.0050.04212.56
5.3.260.0050.04312.62
5.3.250.0070.03012.73
5.3.240.0120.03612.64
5.3.230.0050.04012.60
5.3.220.0030.02212.49
5.3.210.0030.02612.49
5.3.200.0110.02212.52
5.3.190.0020.02712.55
5.3.180.0060.03612.75
5.3.170.0070.03812.65
5.3.160.0020.02312.71
5.3.150.0080.03812.73
5.3.140.0080.04312.68
5.3.130.0080.03712.61
5.3.120.0010.02912.61
5.3.110.0030.02912.58
5.3.100.0020.03612.33
5.3.90.0100.03712.46
5.3.80.0060.03012.35
5.3.70.0030.02912.35
5.3.60.0070.02712.34
5.3.50.0060.02312.28
5.3.40.0000.02512.22
5.3.30.0040.03812.23
5.3.20.0050.04012.16
5.3.10.0030.02712.20
5.3.00.0020.04211.99
5.2.170.0000.03311.16
5.2.160.0100.03311.13
5.2.150.0030.03011.20
5.2.140.0000.04711.19
5.2.130.0030.03711.26
5.2.120.0000.06311.04
5.2.110.0070.06011.07
5.2.100.0170.05711.03
5.2.90.0030.06011.16
5.2.80.0100.05711.07
5.2.70.0030.06711.14
5.2.60.0100.06011.05
5.2.50.0030.06311.10
5.2.40.0000.03710.95
5.2.30.0000.06711.01
5.2.20.0030.06310.97
5.2.10.0030.03710.88
5.2.00.0000.06310.72
5.1.60.0030.02710.14
5.1.50.0070.0539.98
5.1.40.0100.05010.05
5.1.30.0070.05310.31
5.1.20.0000.06010.36
5.1.10.0030.0409.98
5.1.00.0000.03010.07
5.0.50.0000.0408.52
5.0.40.0030.0438.48
5.0.30.0030.0378.27
5.0.20.0000.0208.19
5.0.10.0070.0408.18
5.0.00.0070.0608.21
4.4.90.0030.0308.02
4.4.80.0030.0238.02
4.4.70.0100.0308.02
4.4.60.0030.0308.02
4.4.50.0000.0278.02
4.4.40.0030.0538.02
4.4.30.0030.0308.02
4.4.20.0030.0338.02
4.4.10.0000.0378.02
4.4.00.0030.0538.02
4.3.110.0070.0208.02
4.3.100.0000.0178.02
4.3.90.0030.0138.02
4.3.80.0030.0538.02
4.3.70.0070.0238.02
4.3.60.0000.0378.02
4.3.50.0030.0238.02
4.3.40.0030.0478.02
4.3.30.0000.0338.02
4.3.20.0000.0378.02
4.3.10.0000.0378.02
4.3.00.0000.0238.02

preferences:
53.32 ms | 401 KiB | 5 Q