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 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, $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.00718.43
8.3.50.0130.00821.99
8.3.40.0100.01018.93
8.3.30.0100.00320.35
8.3.20.0080.00020.24
8.3.10.0000.00822.10
8.3.00.0050.00322.40
8.2.180.0100.01016.38
8.2.170.0070.00722.96
8.2.160.0070.00722.21
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00420.88
8.2.110.0090.00022.10
8.2.100.0080.00417.97
8.2.90.0040.00419.21
8.2.80.0000.01119.36
8.2.70.0040.00417.75
8.2.60.0040.00418.04
8.2.50.0030.00618.07
8.2.40.0030.00520.07
8.2.30.0040.00419.37
8.2.20.0040.00418.01
8.2.10.0040.00418.05
8.2.00.0000.01018.05
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.77
8.1.230.0080.00419.34
8.1.220.0060.00317.83
8.1.210.0050.00318.77
8.1.200.0060.00317.38
8.1.190.0060.00317.54
8.1.180.0040.00419.26
8.1.170.0040.00418.86
8.1.160.0100.00018.82
8.1.150.0040.00418.70
8.1.140.0030.00517.52
8.1.130.0000.00720.14
8.1.120.0040.00417.70
8.1.110.0050.00217.64
8.1.100.0080.00017.47
8.1.90.0070.00017.67
8.1.80.0000.00817.65
8.1.70.0040.00417.66
8.1.60.0080.00017.77
8.1.50.0040.00417.66
8.1.40.0040.00417.63
8.1.30.0050.00317.72
8.1.20.0040.00417.90
8.1.10.0050.00517.72
8.1.00.0060.00317.74
8.0.300.0050.00318.90
8.0.290.0000.00717.30
8.0.280.0030.00318.42
8.0.270.0000.00817.31
8.0.260.0000.00720.10
8.0.250.0070.00017.10
8.0.240.0000.00817.11
8.0.230.0040.00416.98
8.0.220.0030.00317.01
8.0.210.0000.00717.06
8.0.200.0040.00417.09
8.0.190.0060.00317.14
8.0.180.0000.00717.08
8.0.170.0040.00416.94
8.0.160.0040.00417.06
8.0.150.0080.00017.10
8.0.140.0080.00017.06
8.0.130.0030.00313.46
8.0.120.0050.00317.02
8.0.110.0000.00817.02
8.0.100.0000.00717.12
8.0.90.0000.00717.14
8.0.80.0120.00917.13
8.0.70.0000.00817.10
8.0.60.0000.00817.01
8.0.50.0040.00417.00
8.0.30.0050.01417.20
8.0.20.0110.00817.40
8.0.10.0040.00416.99
8.0.00.0100.01017.19
7.4.330.0020.00215.09
7.4.320.0030.00316.66
7.4.300.0060.00016.89
7.4.290.0070.00016.75
7.4.280.0030.00316.74
7.4.270.0000.00716.71
7.4.260.0050.00013.48
7.4.250.0040.00416.82
7.4.240.0050.00216.86
7.4.230.0040.00416.84
7.4.220.0060.01216.89
7.4.210.0080.00816.79
7.4.200.0000.00716.76
7.4.190.0000.00716.89
7.4.160.0100.00616.82
7.4.150.0100.00717.40
7.4.140.0050.01317.86
7.4.130.0090.00916.73
7.4.120.0110.00716.76
7.4.110.0190.00016.95
7.4.100.0110.00516.96
7.4.90.0140.00316.66
7.4.80.0150.00619.39
7.4.70.0100.00616.79
7.4.60.0100.01316.84
7.4.50.0000.00816.52
7.4.40.0000.01422.77
7.4.30.0100.00716.67
7.4.10.0060.01015.03
7.4.00.0060.00915.07
7.3.330.0000.00513.41
7.3.320.0000.00513.36
7.3.310.0040.00416.37
7.3.300.0030.00516.57
7.3.290.0030.01016.45
7.3.280.0120.00816.58
7.3.270.0100.00717.40
7.3.260.0070.01516.46
7.3.250.0100.00816.61
7.3.240.0100.00716.68
7.3.230.0100.00716.48
7.3.210.0060.01316.52
7.3.200.0090.00919.39
7.3.190.0080.01116.74
7.3.180.0060.01016.68
7.3.170.0070.01116.82
7.3.160.0080.00916.89
7.3.130.0090.00915.09
7.3.120.0100.00715.09
7.3.110.0120.00615.00
7.3.100.0080.00415.35
7.3.90.0080.00315.00
7.3.80.0040.01115.19
7.3.70.0040.01115.09
7.3.60.0040.01115.00
7.3.50.0110.00415.18
7.3.40.0040.00414.86
7.3.30.0060.00614.96
7.3.20.0040.00816.98
7.3.10.0100.00616.67
7.3.00.0080.00616.74
7.2.330.0060.01216.84
7.2.320.0100.00717.00
7.2.310.0070.01116.79
7.2.300.0090.01216.75
7.2.290.0140.00316.95
7.2.260.0070.01014.91
7.2.250.0120.00615.46
7.2.240.0070.00714.99
7.2.230.0060.00915.38
7.2.220.0040.01115.14
7.2.210.0000.00915.30
7.2.200.0040.00815.49
7.2.190.0030.00715.29
7.2.180.0030.00915.30
7.2.170.0070.00715.18
7.2.160.0100.00715.36
7.2.150.0030.01017.11
7.2.140.0100.00617.25
7.2.130.0020.01217.07
7.2.120.0070.00817.05
7.2.110.0050.00917.02
7.2.100.0080.00617.13
7.2.90.0120.00616.90
7.2.80.0070.00717.03
7.2.70.0090.00717.11
7.2.60.0070.00517.22
7.2.50.0050.00816.90
7.2.40.0040.01017.14
7.2.30.0100.00617.06
7.2.20.0030.01317.23
7.2.10.0070.00817.15
7.2.00.0040.01018.05
7.1.330.0110.00416.06
7.1.320.0090.00616.22
7.1.310.0000.01515.92
7.1.300.0030.01315.87
7.1.290.0100.00315.98
7.1.280.0100.00615.69
7.1.270.0070.00716.12
7.1.260.0080.00415.80
7.1.250.0110.00615.93
7.1.240.0060.00616.01
7.1.230.0030.00716.08
7.1.220.0060.00915.72
7.1.210.0040.00816.09
7.1.200.0070.00715.93
7.1.190.0000.01415.97
7.1.180.0030.01015.61
7.1.170.0000.01116.04
7.1.160.0040.01116.00
7.1.150.0060.00915.98
7.1.140.0000.01116.01
7.1.130.0090.00616.16
7.1.120.0060.00916.01
7.1.110.0030.00616.04
7.1.100.0030.01016.89
7.1.90.0070.01015.95
7.1.80.0000.01315.88
7.1.70.0010.00916.63
7.1.60.0030.01016.90
7.1.50.0080.01016.53
7.1.40.0030.00716.20
7.1.30.0000.01016.15
7.1.20.0040.01116.10
7.1.10.0030.01116.05
7.1.00.0020.04119.09
7.0.330.0080.00315.52
7.0.320.0070.00715.50
7.0.310.0040.01115.33
7.0.300.0000.01415.70
7.0.290.0130.00315.73
7.0.280.0070.00715.66
7.0.270.0080.00415.68
7.0.260.0070.00315.32
7.0.250.0080.00815.85
7.0.240.0000.01215.66
7.0.230.0090.00615.64
7.0.220.0000.01215.44
7.0.210.0040.00815.48
7.0.200.0040.00816.13
7.0.190.0000.01215.78
7.0.180.0040.00815.28
7.0.170.0000.00815.64
7.0.160.0070.00715.50
7.0.150.0000.00815.36
7.0.140.0070.03818.83
7.0.130.0040.00415.56
7.0.120.0150.00015.70
7.0.110.0130.03717.91
7.0.100.0070.03917.76
7.0.90.0090.04217.88
7.0.80.0090.04317.68
7.0.70.0080.02917.84
7.0.60.0120.03917.90
7.0.50.0090.04417.76
7.0.40.0080.04216.65
7.0.30.0060.03816.75
7.0.20.0050.04116.75
7.0.10.0070.04316.67
7.0.00.0100.03816.69
5.6.400.0060.00314.46
5.6.390.0090.00614.50
5.6.380.0130.00314.73
5.6.370.0100.00314.70
5.6.360.0110.00614.60
5.6.350.0110.00714.53
5.6.340.0100.00614.43
5.6.330.0070.00714.34
5.6.320.0070.00314.71
5.6.310.0070.00314.61
5.6.300.0040.01214.14
5.6.290.0060.00914.48
5.6.280.0000.00914.54
5.6.270.0120.00314.47
5.6.260.0050.04417.52
5.6.250.0060.04017.62
5.6.240.0050.04417.54
5.6.230.0090.04417.63
5.6.220.0030.04617.38
5.6.210.0050.04217.61
5.6.200.0080.03717.66
5.6.190.0120.03317.51
5.6.180.0080.04617.53
5.6.170.0050.04817.63
5.6.160.0060.04117.64
5.6.150.0120.04017.53
5.6.140.0070.02817.71
5.6.130.0190.03717.59
5.6.120.0070.04817.47
5.6.110.0020.03417.53
5.6.100.0030.02717.46
5.6.90.0020.03017.54
5.6.80.0050.02517.29
5.6.70.0110.02017.35
5.6.60.0020.02817.33
5.6.50.0080.04217.10
5.6.40.0050.04717.26
5.6.30.0070.04417.22
5.6.20.0060.02317.11
5.6.10.0050.02517.17
5.6.00.0030.02617.23
5.5.380.0000.02615.97
5.5.370.0030.02416.09
5.5.360.0090.04216.21
5.5.350.0120.03815.95
5.5.340.0130.03816.37
5.5.330.0100.04216.35
5.5.320.0100.04316.41
5.5.310.0050.04516.18
5.5.300.0070.04516.24
5.5.290.0100.04216.08
5.5.280.0100.03916.08
5.5.270.0030.02716.21
5.5.260.0040.02316.31
5.5.250.0080.02616.30
5.5.240.0030.04216.02
5.5.230.0070.02515.91
5.5.220.0050.02315.95
5.5.210.0070.04315.96
5.5.200.0070.03815.72
5.5.190.0040.02515.86
5.5.180.0070.03515.84
5.5.170.0110.00314.53
5.5.160.0050.03615.85
5.5.150.0080.03015.87
5.5.140.0080.02315.70
5.5.130.0080.02315.90
5.5.120.0130.02215.95
5.5.110.0060.04315.85
5.5.100.0080.02015.95
5.5.90.0040.02215.81
5.5.80.0040.02215.78
5.5.70.0000.03715.90
5.5.60.0040.02215.94
5.5.50.0040.02115.73
5.5.40.0030.02315.81
5.5.30.0050.02015.88
5.5.20.0000.03215.88
5.5.10.0030.02215.76
5.5.00.0050.02315.82
5.4.450.0070.03915.90
5.4.440.0030.02516.02
5.4.430.0000.02815.89
5.4.420.0060.02216.05
5.4.410.0060.02715.99
5.4.400.0000.02715.71
5.4.390.0050.03015.74
5.4.380.0030.03015.75
5.4.370.0050.02515.73
5.4.360.0180.02015.73
5.4.350.0100.03215.89
5.4.340.0070.03815.72
5.4.330.0000.00712.46
5.4.320.0120.02715.71
5.4.310.0050.02515.73
5.4.300.0030.02515.91
5.4.290.0130.01515.80
5.4.280.0030.02215.85
5.4.270.0070.02715.78
5.4.260.0020.02715.82
5.4.250.0030.02615.85
5.4.240.0060.01815.74
5.4.230.0030.02315.82
5.4.220.0070.03215.81
5.4.210.0080.01915.75
5.4.200.0020.02415.80
5.4.190.0060.02115.82
5.4.180.0070.04115.82
5.4.170.0050.02115.72
5.4.160.0030.02315.85
5.4.150.0020.02015.72
5.4.140.0080.01714.54
5.4.130.0020.02214.43
5.4.120.0050.03314.57
5.4.110.0050.02014.46
5.4.100.0050.02014.50
5.4.90.0070.03714.54
5.4.80.0050.03814.49
5.4.70.0050.04014.53
5.4.60.0020.04014.52
5.4.50.0020.04314.52
5.4.40.0070.04214.56
5.4.30.0030.03514.49
5.4.20.0060.02014.50
5.4.10.0110.01614.49
5.4.00.0030.04414.15
5.3.290.0030.02413.59
5.3.280.0050.01813.62
5.3.270.0050.02713.60
5.3.260.0030.02113.56
5.3.250.0020.02213.67
5.3.240.0020.02513.63
5.3.230.0080.02113.56
5.3.220.0020.02413.54
5.3.210.0040.03413.53
5.3.200.0000.02213.55
5.3.190.0060.02013.60
5.3.180.0100.03313.54
5.3.170.0060.03313.55
5.3.160.0060.04313.65
5.3.150.0090.03913.60
5.3.140.0040.03913.59
5.3.130.0050.03013.60
5.3.120.0090.03813.46
5.3.110.0050.02513.54
5.3.100.0060.02213.20
5.3.90.0020.02013.30
5.3.80.0070.03213.34
5.3.70.0080.01313.37
5.3.60.0050.01713.27
5.3.50.0050.02513.27
5.3.40.0010.03013.24
5.3.30.0030.03313.20
5.3.20.0030.02013.03
5.3.10.0000.02113.08
5.3.00.0030.03013.14
5.2.170.0070.06012.21
5.2.160.0030.05712.21
5.2.150.0000.03012.21
5.2.140.0070.02712.21
5.2.130.0070.02312.21
5.2.120.0070.03712.21
5.2.110.0070.03312.21
5.2.100.0100.05312.21
5.2.90.0030.05712.21
5.2.80.0030.05012.21
5.2.70.0000.03312.21
5.2.60.0070.02312.21
5.2.50.0070.06712.21
5.2.40.0000.05312.21
5.2.30.0000.04712.21
5.2.20.0030.05312.21
5.2.10.0100.05312.21
5.2.00.0030.06012.21
5.1.60.0030.05312.21
5.1.50.0030.02012.21
5.1.40.0100.01712.21
5.1.30.0100.02012.21
5.1.20.0000.03012.21
5.1.10.0130.01712.21
5.1.00.0000.04712.21
5.0.50.0100.03712.21
5.0.40.0000.04012.21
5.0.30.0000.06012.21
5.0.20.0000.04312.21
5.0.10.0000.02312.21
5.0.00.0000.02712.21
4.4.90.0000.01312.21
4.4.80.0030.02012.21
4.4.70.0030.01312.21
4.4.60.0030.01712.21
4.4.50.0000.01712.21
4.4.40.0000.02312.21
4.4.30.0000.02312.21
4.4.20.0000.01312.21
4.4.10.0000.01312.21
4.4.00.0030.02312.21
4.3.110.0000.02312.21
4.3.100.0030.01312.21
4.3.90.0000.01312.21
4.3.80.0030.05012.21
4.3.70.0000.02712.21
4.3.60.0000.03012.21
4.3.50.0070.02312.21
4.3.40.0030.02012.21
4.3.30.0000.03312.21
4.3.20.0030.02012.21
4.3.10.0000.01712.21
4.3.00.0000.03312.21

preferences:
62.12 ms | 400 KiB | 5 Q