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($offset); var_dump(substr($haystack, $offset)); // 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.0110.00418.30
8.3.50.0150.00822.05
8.3.40.0090.00618.96
8.3.30.0100.00320.39
8.3.20.0040.00420.21
8.3.10.0050.00321.96
8.3.00.0040.00422.37
8.2.180.0080.00816.88
8.2.170.0110.00422.96
8.2.160.0100.00322.22
8.2.150.0080.00024.18
8.2.140.0030.00624.66
8.2.130.0000.00826.16
8.2.120.0080.00020.94
8.2.110.0040.00420.52
8.2.100.0060.00618.03
8.2.90.0000.00819.41
8.2.80.0040.00419.38
8.2.70.0050.00317.75
8.2.60.0040.00417.92
8.2.50.0030.00518.07
8.2.40.0000.00820.19
8.2.30.0070.00019.47
8.2.20.0040.00417.89
8.2.10.0000.00817.81
8.2.00.0000.01017.99
8.1.280.0110.00725.92
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0050.00228.09
8.1.240.0090.00023.71
8.1.230.0100.00618.96
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0000.01017.48
8.1.190.0030.00517.50
8.1.180.0080.00019.26
8.1.170.0090.00018.76
8.1.160.0040.00818.98
8.1.150.0070.00318.77
8.1.140.0000.00717.67
8.1.130.0000.00717.89
8.1.120.0080.00017.67
8.1.110.0000.00717.63
8.1.100.0050.00317.65
8.1.90.0040.00417.53
8.1.80.0040.00417.62
8.1.70.0000.00717.63
8.1.60.0040.00417.75
8.1.50.0030.00617.60
8.1.40.0030.00617.71
8.1.30.0030.00517.86
8.1.20.0030.00717.81
8.1.10.0030.00617.65
8.1.00.0040.00417.69
8.0.300.0040.00418.77
8.0.290.0070.00016.92
8.0.280.0040.00418.46
8.0.270.0000.00717.30
8.0.260.0000.00717.04
8.0.250.0000.00717.02
8.0.240.0000.00817.03
8.0.230.0030.00317.10
8.0.220.0000.00817.09
8.0.210.0070.00017.05
8.0.200.0060.00317.14
8.0.190.0060.00317.04
8.0.180.0040.00417.04
8.0.170.0000.00717.05
8.0.160.0040.00417.07
8.0.150.0030.00517.13
8.0.140.0040.00417.01
8.0.130.0070.00013.50
8.0.120.0080.00016.90
8.0.110.0000.00816.97
8.0.100.0040.00417.13
8.0.90.0050.00317.09
8.0.80.0000.01717.00
8.0.70.0070.00017.16
8.0.60.0000.00717.09
8.0.50.0040.00416.95
8.0.30.0110.00917.56
8.0.20.0090.01017.40
8.0.10.0030.00516.97
8.0.00.0070.01417.07
7.4.330.0040.00015.00
7.4.320.0000.00716.79
7.4.300.0030.00316.86
7.4.290.0000.00716.86
7.4.280.0030.00316.63
7.4.270.0070.00016.80
7.4.260.0030.00613.57
7.4.250.0040.00416.71
7.4.240.0020.00516.71
7.4.230.0070.00016.96
7.4.220.0100.01016.89
7.4.210.0060.01116.83
7.4.200.0000.00716.85
7.4.190.0030.00516.71
7.4.160.0090.00616.79
7.4.150.0100.00717.40
7.4.140.0120.00617.86
7.4.130.0080.00916.83
7.4.120.0040.01416.70
7.4.110.0090.00916.83
7.4.100.0070.01716.78
7.4.90.0120.00616.78
7.4.80.0120.00619.39
7.4.70.0030.01316.70
7.4.60.0130.00916.83
7.4.50.0000.00916.80
7.4.40.0040.01422.77
7.4.30.0130.00416.85
7.4.00.0040.01415.26
7.3.330.0000.00513.32
7.3.320.0050.00013.53
7.3.310.0000.00816.44
7.3.300.0030.00316.53
7.3.290.0090.00916.56
7.3.280.0090.01016.53
7.3.270.0080.01017.40
7.3.260.0150.00416.58
7.3.250.0110.00716.64
7.3.240.0090.00916.59
7.3.230.0110.01116.69
7.3.210.0080.00816.52
7.3.200.0140.01019.39
7.3.190.0090.01216.55
7.3.180.0000.01616.82
7.3.170.0100.00616.96
7.3.160.0070.01016.63
7.3.120.0080.00815.16
7.3.110.0090.00814.96
7.3.100.0050.01214.93
7.3.90.0040.00814.98
7.3.80.0060.00615.00
7.3.70.0050.00715.21
7.3.60.0060.00715.04
7.3.50.0090.00215.05
7.3.40.0070.00714.93
7.3.30.0040.00714.99
7.3.20.0070.00516.90
7.3.10.0080.00516.89
7.3.00.0040.00916.71
7.2.330.0110.00717.00
7.2.320.0070.01416.67
7.2.310.0110.00816.87
7.2.300.0150.00816.79
7.2.290.0100.01316.95
7.2.250.0080.01015.05
7.2.240.0050.01015.27
7.2.230.0100.00715.20
7.2.220.0090.00615.26
7.2.210.0030.01015.32
7.2.200.0050.01115.37
7.2.190.0030.00815.40
7.2.180.0030.01215.27
7.2.170.0080.00615.16
7.2.160.0060.00915.51
7.2.150.0070.00717.11
7.2.140.0060.00917.02
7.2.130.0100.00517.02
7.2.120.0050.00917.05
7.2.110.0070.00717.01
7.2.100.0060.00816.94
7.2.90.0110.00517.14
7.2.80.0070.00616.88
7.2.70.0070.00916.93
7.2.60.0090.00616.91
7.2.50.0070.01016.95
7.2.40.0070.01016.98
7.2.30.0100.00617.13
7.2.20.0070.01016.85
7.2.10.0100.00317.10
7.2.00.0080.00717.78
7.1.330.0080.00815.96
7.1.320.0060.01115.99
7.1.310.0050.00516.06
7.1.300.0050.00515.99
7.1.290.0070.00715.98
7.1.280.0050.00715.92
7.1.270.0040.01116.06
7.1.260.0090.00516.02
7.1.250.0060.00815.87
7.1.240.0000.01315.82
7.1.230.0000.00916.06
7.1.220.0100.00716.06
7.1.210.0030.01016.11
7.1.200.0030.01016.07
7.1.190.0030.01215.96
7.1.180.0030.01016.14
7.1.170.0040.00716.06
7.1.160.0000.01416.00
7.1.150.0070.00716.19
7.1.140.0000.01015.97
7.1.130.0080.00615.63
7.1.120.0030.01315.92
7.1.110.0100.00316.15
7.1.100.0030.01016.03
7.1.90.0090.00615.96
7.1.80.0060.00916.15
7.1.70.0070.00516.49
7.1.60.0030.01016.79
7.1.50.0030.01016.44
7.1.40.0000.01115.92
7.1.30.0000.01316.10
7.1.20.0040.00816.03
7.1.10.0040.01216.15
7.1.00.0070.03919.34
7.0.330.0090.00315.52
7.0.320.0090.00615.42
7.0.310.0060.00615.27
7.0.300.0070.00315.59
7.0.290.0070.00715.73
7.0.280.0070.00715.58
7.0.270.0070.00715.40
7.0.260.0000.01315.77
7.0.250.0030.01015.47
7.0.240.0000.01615.40
7.0.230.0040.00915.73
7.0.220.0070.01015.32
7.0.210.0000.01415.57
7.0.200.0020.00916.14
7.0.190.0000.01415.23
7.0.180.0100.00015.52
7.0.170.0000.01515.84
7.0.160.0030.01015.40
7.0.150.0030.01015.54
7.0.140.0060.04118.77
7.0.130.0060.00915.48
7.0.120.0060.00815.67
7.0.110.0070.00415.75
7.0.100.0090.04117.65
7.0.90.0250.04017.87
7.0.80.0170.04617.83
7.0.70.0170.04517.70
7.0.60.0180.04517.65
7.0.50.0300.03518.04
7.0.40.0100.04116.87
7.0.30.0030.04816.86
7.0.20.0080.03816.88
7.0.10.0040.04616.91
7.0.00.0050.04516.76
5.6.400.0000.00814.77
5.6.390.0090.00614.48
5.6.380.0030.01014.22
5.6.370.0070.00714.60
5.6.360.0090.00314.21
5.6.350.0030.01214.40
5.6.340.0120.00414.85
5.6.330.0100.00714.28
5.6.320.0040.00414.80
5.6.310.0150.00014.70
5.6.300.0070.00714.57
5.6.290.0000.01414.23
5.6.280.0060.04017.78
5.6.270.0030.01014.70
5.6.260.0080.00614.20
5.6.250.0070.03917.74
5.6.240.0080.04517.46
5.6.230.0120.04517.58
5.6.220.0070.02417.58
5.6.210.0050.04417.42
5.6.200.0070.03717.67
5.6.190.0000.04717.77
5.6.180.0120.04017.92
5.6.170.0070.04717.85
5.6.160.0080.04717.70
5.6.150.0060.04017.76
5.6.140.0110.03817.73
5.6.130.0030.04817.65
5.6.120.0110.04017.80
5.6.110.0070.04417.80
5.6.100.0100.04717.71
5.6.90.0070.04017.71
5.6.80.0050.04317.42
5.6.70.0030.04917.34
5.6.60.0090.04217.41
5.6.50.0120.04017.42
5.6.40.0130.02717.39
5.6.30.0050.04417.28
5.6.20.0020.03817.44
5.6.10.0080.04317.51
5.6.00.0050.05017.32
5.5.380.0090.04417.39
5.5.370.0000.03917.26
5.5.360.0070.04517.58
5.5.350.0080.03617.49
5.5.340.0030.04117.58
5.5.330.0080.04017.54
5.5.320.0080.04317.67
5.5.310.0080.04217.68
5.5.300.0060.04917.62
5.5.290.0130.04017.68
5.5.280.0070.04317.69
5.5.270.0080.04617.42
5.5.260.0060.02317.68
5.5.250.0060.04317.45
5.5.240.0050.04517.38
5.5.230.0030.04817.41
5.5.220.0100.03517.28
5.5.210.0100.04317.34
5.5.200.0150.04017.13
5.5.190.0020.04217.29
5.5.180.0030.03017.12
5.5.170.0060.00614.54
5.5.160.0100.03817.36
5.5.150.0120.03717.33
5.5.140.0030.05317.31
5.5.130.0050.04317.30
5.5.120.0130.04017.15
5.5.110.0080.04117.30
5.5.100.0090.02317.06
5.5.90.0050.04017.21
5.5.80.0030.04917.35
5.5.70.0000.03617.21
5.5.60.0090.03817.14
5.5.50.0050.03017.09
5.5.40.0070.04217.11
5.5.30.0140.04217.06
5.5.20.0050.04717.13
5.5.10.0060.04017.22
5.5.00.0000.05017.02
5.4.450.0080.03615.81
5.4.440.0040.04215.69
5.4.430.0050.04015.74
5.4.420.0040.03715.64
5.4.410.0050.04015.73
5.4.400.0080.04015.60
5.4.390.0100.02215.67
5.4.380.0050.03315.48
5.4.370.0030.04215.48
5.4.360.0030.04115.64
5.4.350.0030.02615.57
5.4.340.0050.04015.49
5.4.330.0040.00712.11
5.4.320.0140.03315.53
5.4.310.0070.03615.60
5.4.300.0080.03515.67
5.4.290.0100.03715.53
5.4.280.0030.02915.66
5.4.270.0030.03815.48
5.4.260.0110.03515.49
5.4.250.0100.03515.57
5.4.240.0050.02515.56
5.4.230.0050.04315.62
5.4.220.0040.02915.67
5.4.210.0100.03315.63
5.4.200.0050.04215.64
5.4.190.0030.04315.52
5.4.180.0020.03215.61
5.4.170.0120.03815.62
5.4.160.0100.03815.61
5.4.150.0080.03415.57
5.4.140.0060.04114.27
5.4.130.0080.03614.26
5.4.120.0080.02214.15
5.4.110.0020.04314.30
5.4.100.0050.03814.28
5.4.90.0050.03914.26
5.4.80.0090.03514.24
5.4.70.0070.03514.29
5.4.60.0000.04314.29
5.4.50.0050.02214.29
5.4.40.0080.04014.25
5.4.30.0080.03814.25
5.4.20.0080.03814.28
5.4.10.0120.03714.32
5.4.00.0050.03714.00
5.3.290.0050.04013.43
5.3.280.0070.04213.37
5.3.270.0100.03713.34
5.3.260.0060.02513.40
5.3.250.0030.02713.38
5.3.240.0050.02413.38
5.3.230.0030.03813.40
5.3.220.0090.02513.41
5.3.210.0070.03513.41
5.3.200.0000.04013.42
5.3.190.0070.04213.35
5.3.180.0090.03513.34
5.3.170.0000.03113.33
5.3.160.0050.04113.36
5.3.150.0100.03713.40
5.3.140.0020.02513.40
5.3.130.0050.03013.41
5.3.120.0060.02513.35
5.3.110.0050.03813.35
5.3.100.0030.03613.06
5.3.90.0020.02513.09
5.3.80.0060.04013.06
5.3.70.0020.02513.02
5.3.60.0080.03513.04
5.3.50.0030.03013.05
5.3.40.0020.04613.07
5.3.30.0080.03313.08
5.3.20.0020.04412.87
5.3.10.0050.02712.90
5.3.00.0020.03512.89
5.2.170.0100.04312.09
5.2.160.0100.05712.09
5.2.150.0100.07012.09
5.2.140.0070.04312.09
5.2.130.0030.06312.09
5.2.120.0070.06012.09
5.2.110.0000.06712.09
5.2.100.0000.06712.09
5.2.90.0000.06312.09
5.2.80.0170.05012.09
5.2.70.0070.03712.09
5.2.60.0000.06312.09
5.2.50.0030.05712.09
5.2.40.0030.03312.09
5.2.30.0030.06312.09
5.2.20.0070.05312.09
5.2.10.0000.06312.09
5.2.00.0000.05712.09
5.1.60.0100.05012.09
5.1.50.0100.05012.09
5.1.40.0070.03712.09
5.1.30.0030.06012.09
5.1.20.0000.06012.09
5.1.10.0070.04312.09
5.1.00.0100.05312.09
5.0.50.0000.04312.09
5.0.40.0100.04012.09
5.0.30.0000.06712.09
5.0.20.0000.04712.09
5.0.10.0070.02312.09
5.0.00.0130.06012.09
4.4.90.0000.03712.09
4.4.80.0000.03712.09
4.4.70.0000.02012.09
4.4.60.0070.03012.09
4.4.50.0000.03312.09
4.4.40.0030.05312.09
4.4.30.0000.03712.09
4.4.20.0030.03312.09
4.4.10.0030.03712.09
4.4.00.0030.03312.09
4.3.110.0030.03312.09
4.3.100.0000.03712.09
4.3.90.0000.03312.09
4.3.80.0000.05712.09
4.3.70.0000.03712.09
4.3.60.0030.03312.09
4.3.50.0000.04012.09
4.3.40.0030.04012.09
4.3.30.0030.03712.09
4.3.20.0000.03712.09
4.3.10.0070.03012.09
4.3.00.0000.03712.09

preferences:
41.14 ms | 401 KiB | 5 Q