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++; } 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.01318.43
8.3.50.0180.00321.33
8.3.40.0110.00418.76
8.3.30.0100.00320.18
8.3.20.0000.00720.20
8.3.10.0080.00022.04
8.3.00.0030.00522.52
8.2.180.0030.01516.88
8.2.170.0060.00922.96
8.2.160.0130.00722.21
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0080.00021.06
8.2.110.0030.00622.38
8.2.100.0040.00718.03
8.2.90.0050.00319.17
8.2.80.0040.00419.41
8.2.70.0090.00017.75
8.2.60.0090.00017.93
8.2.50.0000.00818.07
8.2.40.0040.00420.07
8.2.30.0050.00319.50
8.2.20.0000.00817.84
8.2.10.0000.00817.87
8.2.00.0060.00317.89
8.1.280.0090.01225.92
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0070.00323.80
8.1.230.0110.00019.22
8.1.220.0100.00017.89
8.1.210.0050.00318.77
8.1.200.0070.00317.60
8.1.190.0050.00317.53
8.1.180.0040.00419.14
8.1.170.0000.00818.82
8.1.160.0080.00318.83
8.1.150.0040.00418.74
8.1.140.0070.00017.52
8.1.130.0000.00717.84
8.1.120.0040.00417.55
8.1.110.0030.00517.67
8.1.100.0000.00717.54
8.1.90.0000.00717.58
8.1.80.0000.00717.63
8.1.70.0030.00317.46
8.1.60.0060.00317.72
8.1.50.0000.00817.76
8.1.40.0030.00617.57
8.1.30.0060.00317.71
8.1.20.0000.00817.82
8.1.10.0080.00017.67
8.1.00.0040.00417.61
8.0.300.0070.00018.77
8.0.290.0080.00017.18
8.0.280.0030.00318.56
8.0.270.0000.00717.31
8.0.260.0030.00316.88
8.0.250.0030.00317.01
8.0.240.0000.00917.13
8.0.230.0040.00417.06
8.0.220.0070.00017.03
8.0.210.0040.00417.04
8.0.200.0000.00817.13
8.0.190.0000.00817.04
8.0.180.0030.00617.06
8.0.170.0030.00516.99
8.0.160.0070.00017.11
8.0.150.0000.00717.08
8.0.140.0050.00317.06
8.0.130.0030.00313.44
8.0.120.0050.00316.90
8.0.110.0050.00217.09
8.0.100.0000.00716.96
8.0.90.0040.00417.04
8.0.80.0100.00616.98
8.0.70.0060.00317.02
8.0.60.0000.00716.95
8.0.50.0080.00017.11
8.0.30.0080.01017.28
8.0.20.0110.01217.44
8.0.10.0070.00017.21
8.0.00.0110.00817.08
7.4.330.0000.00515.00
7.4.320.0030.00316.82
7.4.300.0030.00316.80
7.4.290.0070.00016.68
7.4.280.0070.00016.68
7.4.270.0000.00716.72
7.4.260.0030.00313.50
7.4.250.0000.00716.66
7.4.240.0050.00216.79
7.4.230.0000.00716.94
7.4.220.0070.01016.75
7.4.210.0060.01116.81
7.4.200.0040.00416.96
7.4.190.0030.00316.80
7.4.160.0120.00616.66
7.4.150.0130.00617.40
7.4.140.0110.00917.86
7.4.130.0050.01416.79
7.4.120.0120.00616.80
7.4.110.0120.00616.90
7.4.100.0100.00716.88
7.4.90.0150.00916.57
7.4.80.0250.02919.39
7.4.70.0100.00716.61
7.4.60.0120.00916.70
7.4.50.0060.00316.79
7.4.40.0080.00322.77
7.4.30.0100.00716.85
7.4.10.0070.01115.10
7.4.00.0070.01315.25
7.3.330.0050.00013.33
7.3.320.0000.00613.62
7.3.310.0050.00316.45
7.3.300.0070.00016.60
7.3.290.0000.01416.55
7.3.280.0120.00616.55
7.3.270.0090.00817.40
7.3.260.0090.01516.57
7.3.250.0100.00716.61
7.3.240.0110.00716.48
7.3.230.0070.01016.74
7.3.210.0060.01116.61
7.3.200.0060.01419.39
7.3.190.0180.00416.79
7.3.180.0110.00616.64
7.3.170.0100.00616.91
7.3.160.0130.00616.59
7.3.130.0040.01415.24
7.3.120.0100.00715.04
7.3.110.0100.00714.93
7.3.100.0090.00615.06
7.3.90.0050.00615.03
7.3.80.0050.00915.28
7.3.70.0080.00715.06
7.3.60.0060.00814.88
7.3.50.0050.00515.04
7.3.40.0050.01115.02
7.3.30.0080.00315.07
7.3.20.0070.00716.80
7.3.10.0060.00916.83
7.3.00.0110.00316.88
7.2.330.0070.01116.92
7.2.320.0070.01116.96
7.2.310.0090.00916.92
7.2.300.0030.01316.79
7.2.290.0040.01316.98
7.2.260.0170.00015.32
7.2.250.0070.00715.32
7.2.240.0070.00515.13
7.2.230.0030.01415.27
7.2.220.0020.01315.42
7.2.210.0040.00915.39
7.2.200.0080.00515.23
7.2.190.0040.00715.32
7.2.180.0060.00915.37
7.2.170.0030.00815.19
7.2.160.0050.00815.30
7.2.150.0090.00417.23
7.2.140.0040.01117.18
7.2.130.0070.00917.05
7.2.120.0080.01117.15
7.2.110.0090.00717.12
7.2.100.0080.01117.19
7.2.90.0060.00917.18
7.2.80.0040.01017.17
7.2.70.0040.01017.13
7.2.60.0050.01317.24
7.2.50.0080.00817.06
7.2.40.0060.00617.26
7.2.30.0060.01317.03
7.2.20.0050.00817.05
7.2.10.0110.00517.12
7.2.00.0080.00917.06
7.1.330.0050.01115.88
7.1.320.0050.00816.19
7.1.310.0030.01116.00
7.1.300.0030.00715.85
7.1.290.0050.00815.95
7.1.280.0030.01115.90
7.1.270.0060.00616.03
7.1.260.0100.00215.97
7.1.250.0070.00615.96
7.1.240.0000.01416.02
7.1.230.0070.00715.75
7.1.220.0090.00915.96
7.1.210.0000.01216.12
7.1.200.0070.00216.05
7.1.190.0080.00415.99
7.1.180.0060.00916.02
7.1.170.0000.00916.15
7.1.160.0030.01316.11
7.1.150.0060.00916.15
7.1.140.0030.01315.95
7.1.130.0070.00715.92
7.1.120.0040.01116.09
7.1.110.0070.00315.95
7.1.100.0030.01015.89
7.1.90.0000.00915.83
7.1.80.0030.00815.94
7.1.70.0030.00816.73
7.1.60.0080.00816.78
7.1.50.0020.01516.57
7.1.40.0000.01415.77
7.1.30.0060.00916.01
7.1.20.0100.00716.06
7.1.10.0100.00616.11
7.1.00.0030.02219.20
7.0.330.0040.00815.80
7.0.320.0100.00315.55
7.0.310.0000.01515.80
7.0.300.0030.01015.58
7.0.290.0040.01115.66
7.0.280.0030.01315.74
7.0.270.0070.00715.57
7.0.260.0000.01015.63
7.0.250.0030.01015.73
7.0.240.0060.00315.51
7.0.230.0060.00615.71
7.0.220.0040.01115.64
7.0.210.0000.01515.49
7.0.200.0020.00916.25
7.0.190.0080.00315.72
7.0.180.0090.00615.70
7.0.170.0040.00415.52
7.0.160.0070.00715.62
7.0.150.0060.00315.60
7.0.140.0020.04218.72
7.0.130.0000.01215.67
7.0.120.0000.01315.67
7.0.110.0040.00415.74
7.0.100.0150.04817.73
7.0.90.0020.04717.78
7.0.80.0050.02617.89
7.0.70.0160.02817.73
7.0.60.0150.04017.77
7.0.50.0100.04217.80
7.0.40.0050.04216.91
7.0.30.0070.02816.87
7.0.20.0100.04317.01
7.0.10.0130.04016.93
7.0.00.0070.04516.90
5.6.400.0070.00414.73
5.6.390.0110.00414.80
5.6.380.0030.01014.63
5.6.370.0090.00614.64
5.6.360.0040.01114.73
5.6.350.0140.00014.49
5.6.340.0000.01414.58
5.6.330.0070.01014.94
5.6.320.0070.00714.75
5.6.310.0040.01114.51
5.6.300.0000.01013.93
5.6.290.0040.00814.76
5.6.280.0030.05217.75
5.6.270.0030.01214.49
5.6.260.0060.00914.43
5.6.250.0070.03417.56
5.6.240.0100.04217.60
5.6.230.0150.03817.51
5.6.220.0100.03317.39
5.6.210.0070.03717.54
5.6.200.0110.04117.81
5.6.190.0040.04817.83
5.6.180.0080.04517.62
5.6.170.0130.04217.79
5.6.160.0070.02717.84
5.6.150.0080.03617.92
5.6.140.0110.03517.87
5.6.130.0020.03617.76
5.6.120.0080.04217.84
5.6.110.0100.04017.84
5.6.100.0090.04217.72
5.6.90.0060.04617.68
5.6.80.0030.04517.50
5.6.70.0120.03517.58
5.6.60.0080.04517.33
5.6.50.0080.04117.63
5.6.40.0080.04217.38
5.6.30.0080.04117.53
5.6.20.0020.04917.42
5.6.10.0080.04317.38
5.6.00.0050.04517.38
5.5.380.0070.03717.57
5.5.370.0080.03517.27
5.5.360.0120.04217.33
5.5.350.0100.02917.43
5.5.340.0050.04417.82
5.5.330.0080.04217.86
5.5.320.0060.04217.54
5.5.310.0080.04317.61
5.5.300.0070.04117.66
5.5.290.0050.04417.59
5.5.280.0110.03517.55
5.5.270.0110.04317.49
5.5.260.0100.04317.52
5.5.250.0200.03517.55
5.5.240.0080.04217.24
5.5.230.0090.04017.14
5.5.220.0050.04717.29
5.5.210.0100.04217.33
5.5.200.0030.03317.26
5.5.190.0070.04217.21
5.5.180.0150.03817.39
5.5.170.0000.01414.44
5.5.160.0080.02517.35
5.5.150.0120.02017.38
5.5.140.0020.02917.34
5.5.130.0060.02317.33
5.5.120.0050.03217.26
5.5.110.0070.02517.28
5.5.100.0030.02817.24
5.5.90.0060.02117.22
5.5.80.0080.03817.27
5.5.70.0050.03217.24
5.5.60.0130.03717.12
5.5.50.0070.04017.27
5.5.40.0030.04317.16
5.5.30.0070.03717.20
5.5.20.0100.04417.10
5.5.10.0050.04917.17
5.5.00.0070.04217.16
5.4.450.0010.03915.73
5.4.440.0100.02415.57
5.4.430.0070.04215.56
5.4.420.0080.03715.66
5.4.410.0020.02615.51
5.4.400.0050.04415.44
5.4.390.0030.04015.56
5.4.380.0050.04215.50
5.4.370.0100.03915.43
5.4.360.0030.02715.57
5.4.350.0070.03315.49
5.4.340.0030.03015.49
5.4.330.0000.00611.95
5.4.320.0030.03715.50
5.4.310.0060.03315.52
5.4.300.0070.03315.54
5.4.290.0080.03115.40
5.4.280.0060.02815.56
5.4.270.0050.04115.45
5.4.260.0100.03115.59
5.4.250.0050.04015.59
5.4.240.0020.03915.52
5.4.230.0020.04215.49
5.4.220.0060.02515.55
5.4.210.0020.04615.40
5.4.200.0050.04115.55
5.4.190.0020.04215.42
5.4.180.0100.04215.49
5.4.170.0090.02515.54
5.4.160.0050.04015.57
5.4.150.0120.03515.50
5.4.140.0050.04114.18
5.4.130.0110.03014.14
5.4.120.0100.03514.18
5.4.110.0050.03814.15
5.4.100.0070.03714.23
5.4.90.0100.03514.26
5.4.80.0070.04214.21
5.4.70.0100.03714.25
5.4.60.0050.03114.16
5.4.50.0030.04314.16
5.4.40.0050.04614.19
5.4.30.0050.02814.20
5.4.20.0080.02214.15
5.4.10.0070.02214.17
5.4.00.0070.03513.91
5.3.290.0040.02313.29
5.3.280.0050.04613.32
5.3.270.0080.02013.29
5.3.260.0070.03813.34
5.3.250.0070.03013.33
5.3.240.0070.03213.28
5.3.230.0110.03613.36
5.3.220.0050.02513.28
5.3.210.0070.03713.25
5.3.200.0030.04313.29
5.3.190.0050.03113.24
5.3.180.0120.03513.24
5.3.170.0080.03613.29
5.3.160.0070.03913.34
5.3.150.0100.03313.33
5.3.140.0050.04313.34
5.3.130.0040.02313.26
5.3.120.0060.04013.25
5.3.110.0070.02513.25
5.3.100.0040.02413.01
5.3.90.0060.02513.00
5.3.80.0050.03812.99
5.3.70.0080.03913.07
5.3.60.0070.02413.03
5.3.50.0070.02812.99
5.3.40.0050.02313.04
5.3.30.0070.02012.99
5.3.20.0060.01812.86
5.3.10.0090.02512.85
5.3.00.0030.02512.80
5.2.170.0000.04712.11
5.2.160.0000.03312.11
5.2.150.0030.03012.11
5.2.140.0000.03712.11
5.2.130.0070.02712.11
5.2.120.0030.02712.11
5.2.110.0030.03012.11
5.2.100.0030.03312.11
5.2.90.0000.03012.11
5.2.80.0030.03012.11
5.2.70.0070.02712.11
5.2.60.0030.03012.11
5.2.50.0070.02712.11
5.2.40.0070.02712.11
5.2.30.0130.02312.11
5.2.20.0070.04012.11
5.2.10.0030.03012.11
5.2.00.0030.03012.11
5.1.60.0070.03312.11
5.1.50.0100.02012.11
5.1.40.0030.03012.11
5.1.30.0030.02712.11
5.1.20.0100.02312.11
5.1.10.0000.02712.11
5.1.00.0000.02712.11
5.0.50.0030.02012.11
5.0.40.0000.02312.11
5.0.30.0000.06312.11
5.0.20.0030.04312.11
5.0.10.0000.02012.11
5.0.00.0000.03312.11
4.4.90.0000.01712.11
4.4.80.0000.02012.11
4.4.70.0000.03012.11
4.4.60.0070.01712.11
4.4.50.0000.02012.11
4.4.40.0030.02312.11
4.4.30.0030.01312.11
4.4.20.0000.01712.11
4.4.10.0000.02012.11
4.4.00.0030.02312.11
4.3.110.0070.01012.11
4.3.100.0000.01712.11
4.3.90.0030.01312.11
4.3.80.0000.02712.11
4.3.70.0000.03012.11
4.3.60.0000.01312.11
4.3.50.0030.02712.11
4.3.40.0000.02312.11
4.3.30.0000.01712.11
4.3.20.0000.01712.11
4.3.10.0030.01012.11
4.3.00.0000.01312.11

preferences:
54.55 ms | 401 KiB | 5 Q