3v4l.org

run code in 300+ PHP versions simultaneously
<?php $message = "This is a string using the terms? Wait here's one\n abukuma 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); // Now find the next occurence $strpos = preg_match($regexp, $haystack, $matches, PREG_OFFSET_CAPTURE, $offset); if ($strpos === false) { return $haystack; } $found = array_search(preg_replace('/' . $wordDelimiter . '/', ' ', $matches[0][0]), $needle); $haystack = substr_replace($haystack, $replacement[$found], $matches[0][1], $matches[0][1] + strlen($match[0][0])); exit; return replaceStrings($haystack, $needle, $replacement, $offset); } 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.01018.80
8.3.50.0140.00821.21
8.3.40.0110.00418.74
8.3.30.0070.01020.17
8.3.20.0050.00220.25
8.3.10.0000.00821.96
8.3.00.0040.00422.32
8.2.180.0040.01118.54
8.2.170.0110.00422.96
8.2.160.0130.00722.06
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00420.80
8.2.110.0090.00022.20
8.2.100.0070.00617.95
8.2.90.0030.00619.40
8.2.80.0080.00019.39
8.2.70.0100.00018.00
8.2.60.0000.00818.04
8.2.50.0040.00418.07
8.2.40.0000.00820.20
8.2.30.0040.00419.48
8.2.20.0000.00817.97
8.2.10.0050.00318.06
8.2.00.0030.00618.05
8.1.270.0000.00823.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00723.93
8.1.230.0040.00819.13
8.1.220.0060.00317.74
8.1.210.0000.00818.77
8.1.200.0030.00617.73
8.1.190.0000.00817.53
8.1.180.0040.00419.13
8.1.170.0040.00418.71
8.1.160.0080.00318.94
8.1.150.0060.00318.73
8.1.140.0050.00217.59
8.1.130.0040.00417.95
8.1.120.0000.00717.67
8.1.110.0040.00417.62
8.1.100.0040.00417.70
8.1.90.0000.00717.70
8.1.80.0050.00217.67
8.1.70.0070.00017.61
8.1.60.0030.00517.80
8.1.50.0000.00917.73
8.1.40.0060.00317.59
8.1.30.0000.00817.71
8.1.20.0050.00317.73
8.1.10.0040.00417.74
8.1.00.0000.00817.61
8.0.300.0050.00218.77
8.0.290.0040.00417.18
8.0.280.0000.00718.50
8.0.270.0040.00417.25
8.0.260.0000.00717.00
8.0.250.0030.00317.13
8.0.240.0080.00017.24
8.0.230.0000.00817.21
8.0.220.0000.00717.20
8.0.210.0070.00017.05
8.0.200.0040.00417.24
8.0.190.0040.00417.09
8.0.180.0040.00417.05
8.0.170.0070.00017.13
8.0.160.0070.00017.09
8.0.150.0020.00517.09
8.0.140.0030.00617.08
8.0.130.0060.00013.57
8.0.120.0000.00817.06
8.0.110.0000.00717.17
8.0.100.0040.00417.10
8.0.90.0000.00717.12
8.0.80.0040.01217.07
8.0.70.0040.00417.00
8.0.60.0070.00017.25
8.0.50.0050.00317.03
8.0.30.0110.01017.21
8.0.20.0170.00517.40
8.0.10.0040.00417.32
8.0.00.0140.00516.81
7.4.330.0050.00015.07
7.4.320.0000.00616.85
7.4.300.0030.00316.74
7.4.290.0000.00716.83
7.4.280.0040.00416.89
7.4.270.0070.00016.84
7.4.260.0000.00713.45
7.4.250.0040.00416.77
7.4.240.0020.00616.79
7.4.230.0000.00716.59
7.4.220.0030.02316.93
7.4.210.0090.00816.75
7.4.200.0000.00716.66
7.4.190.0040.00416.65
7.4.160.0090.00916.86
7.4.150.0090.00917.40
7.4.140.0110.00617.86
7.4.130.0060.01116.71
7.4.120.0150.00316.74
7.4.110.0100.01016.75
7.4.100.0070.01016.88
7.4.90.0120.00616.82
7.4.80.0030.01419.39
7.4.70.0030.01416.75
7.4.60.0090.00916.75
7.4.50.0080.00016.66
7.4.40.0030.01522.77
7.4.30.0100.00716.75
7.4.00.0120.00515.43
7.3.330.0000.00513.57
7.3.320.0000.00513.41
7.3.310.0040.00416.42
7.3.300.0050.00216.47
7.3.290.0030.01216.60
7.3.280.0080.01016.61
7.3.270.0070.01117.40
7.3.260.0120.00816.59
7.3.250.0050.01616.77
7.3.240.0070.01016.64
7.3.230.0070.01016.86
7.3.210.0060.01216.51
7.3.200.0140.00319.39
7.3.190.0060.01016.56
7.3.180.0000.01516.79
7.3.170.0120.00916.85
7.3.160.0080.00816.69
7.3.120.0050.01015.07
7.3.110.0110.00714.98
7.3.100.0030.01415.11
7.3.90.0100.00615.14
7.3.80.0030.01015.07
7.3.70.0040.00815.16
7.3.60.0140.00314.96
7.3.50.0040.01414.89
7.3.40.0070.00715.13
7.3.30.0070.00715.12
7.3.20.0030.01016.71
7.3.10.0070.00716.89
7.3.00.0050.01216.74
7.2.330.0120.00616.71
7.2.320.0120.00616.79
7.2.310.0090.00916.76
7.2.300.0110.00616.79
7.2.290.0130.01016.91
7.2.250.0040.01415.46
7.2.240.0100.01015.22
7.2.230.0050.00515.36
7.2.220.0030.01415.22
7.2.210.0040.01115.39
7.2.200.0000.01314.97
7.2.190.0030.01015.40
7.2.180.0030.01015.17
7.2.170.0000.01115.37
7.2.130.0140.00317.13
7.2.120.0110.01016.91
7.2.110.0080.00817.06
7.2.100.0180.00416.89
7.2.90.0100.00716.86
7.2.80.0140.00317.10
7.2.70.0140.00616.92
7.2.60.0090.00717.03
7.2.50.0140.00716.76
7.2.40.0120.00616.95
7.2.30.0150.00016.86
7.2.20.0160.00317.27
7.2.10.0140.00517.16
7.2.00.0080.00718.50
7.1.330.0060.01016.17
7.1.320.0040.00815.97
7.1.310.0000.00915.69
7.1.300.0000.01415.72
7.1.290.0100.00315.69
7.1.280.0040.00816.14
7.1.270.0080.00816.09
7.1.260.0000.01615.96
7.1.250.0080.01215.77
7.1.240.0100.00716.03
7.1.230.0090.00615.84
7.1.220.0080.00815.78
7.1.210.0030.00616.02
7.1.200.0080.00715.86
7.1.190.0060.00915.78
7.1.180.0080.01316.03
7.1.170.0060.01215.86
7.1.160.0110.00715.66
7.1.150.0090.00915.90
7.1.140.0170.00015.61
7.1.130.0070.01015.93
7.1.120.0100.00716.10
7.1.110.0110.00515.97
7.1.100.0120.00317.16
7.1.90.0140.00415.75
7.1.80.0090.00615.89
7.1.70.0090.00216.64
7.1.60.0090.00216.78
7.1.50.0120.00716.66
7.1.40.0090.00615.85
7.1.30.0150.00015.73
7.1.20.0100.00715.80
7.1.10.0060.00915.96
7.1.00.0050.03119.24
7.0.330.0100.00615.39
7.0.320.0070.00715.52
7.0.310.0110.00415.19
7.0.300.0130.00415.26
7.0.290.0070.01015.61
7.0.280.0120.00315.13
7.0.270.0100.00715.59
7.0.260.0120.00315.69
7.0.250.0090.00615.64
7.0.240.0120.00415.44
7.0.230.0130.00615.29
7.0.220.0070.01115.59
7.0.210.0090.00615.27
7.0.200.0100.00816.26
7.0.190.0110.00415.59
7.0.180.0100.00715.38
7.0.170.0130.00315.35
7.0.160.0070.01015.38
7.0.150.0110.00415.22
7.0.140.0110.03718.63
7.0.130.0100.00715.10
7.0.120.0070.01115.09
7.0.110.0110.00415.62
7.0.100.0080.03817.42
7.0.90.0100.03817.78
7.0.80.0230.04017.54
7.0.70.0150.02817.71
7.0.60.0090.04217.54
7.0.50.0050.02817.92
7.0.40.0030.04916.80
7.0.30.0120.04216.90
7.0.20.0050.04516.61
7.0.10.0120.03816.81
7.0.00.0020.05216.76
5.6.380.0060.00614.50
5.6.370.0060.00614.46
5.6.360.0050.00514.18
5.6.350.0000.01313.99
5.6.340.0060.00914.29
5.6.330.0000.01014.22
5.6.320.0070.00414.73
5.6.310.0000.01114.14
5.6.300.0090.00613.86
5.6.290.0080.00814.16
5.6.280.0090.03617.78
5.6.270.0050.00714.55
5.6.260.0100.00514.54
5.6.250.0080.03517.59
5.6.240.0100.03517.41
5.6.230.0050.02517.38
5.6.220.0120.03717.32
5.6.210.0000.05017.39
5.6.200.0050.05017.56
5.6.190.0040.04017.75
5.6.180.0070.02117.58
5.6.170.0030.04617.55
5.6.160.0100.04217.56
5.6.150.0050.03617.73
5.6.140.0100.02717.68
5.6.130.0050.05117.66
5.6.120.0050.04017.52
5.6.110.0100.04517.62
5.6.100.0060.04017.81
5.6.90.0070.04317.63
5.6.80.0070.04017.47
5.6.70.0080.04017.42
5.6.60.0070.04517.33
5.6.50.0060.04117.27
5.6.40.0090.04317.29
5.6.30.0100.03917.45
5.6.20.0110.02917.25
5.6.10.0120.03517.40
5.6.00.0070.04517.31
5.5.380.0030.04515.83
5.5.370.0040.02715.81
5.5.360.0070.02215.85
5.5.350.0040.03415.91
5.5.340.0080.04316.09
5.5.330.0020.04715.95
5.5.320.0040.02215.82
5.5.310.0050.02916.03
5.5.300.0020.04516.13
5.5.290.0030.05016.01
5.5.280.0060.04316.01
5.5.270.0050.04615.96
5.5.260.0100.04116.11
5.5.250.0060.02715.91
5.5.240.0080.02915.77
5.5.230.0130.03715.72
5.5.220.0080.03715.58
5.5.210.0110.03815.81
5.5.200.0100.04015.53
5.5.190.0030.04815.73
5.5.180.0070.02315.65
5.5.170.0080.00410.94
5.5.160.0070.03915.54
5.5.150.0040.02115.73
5.5.140.0050.02715.70
5.5.130.0070.02315.70
5.5.120.0050.04415.69
5.5.110.0030.03615.62
5.5.100.0030.04915.70
5.5.90.0050.02015.55
5.5.80.0050.04315.59
5.5.70.0040.04315.47
5.5.60.0070.04415.54
5.5.50.0070.02015.70
5.5.40.0090.03015.63
5.5.30.0110.03715.53
5.5.20.0070.03815.73
5.5.10.0070.02915.59
5.5.00.0090.02515.66
5.4.450.0030.02315.14
5.4.440.0120.03815.27
5.4.430.0110.03715.41
5.4.420.0030.03815.40
5.4.410.0070.03915.29
5.4.400.0030.03614.97
5.4.390.0080.03814.84
5.4.380.0060.02815.04
5.4.370.0090.03215.19
5.4.360.0090.03715.05
5.4.350.0050.04215.12
5.4.340.0030.04015.00
5.4.330.0100.00411.16
5.4.320.0050.04215.05
5.4.310.0020.04514.95
5.4.300.0020.03515.02
5.4.290.0040.03615.02
5.4.280.0100.03715.14
5.4.270.0000.04215.03
5.4.260.0020.04515.17
5.4.250.0030.04215.09
5.4.240.0040.04515.10
5.4.230.0100.04115.12
5.4.220.0050.02814.85
5.4.210.0080.03815.21
5.4.200.0080.03614.96
5.4.190.0050.04315.04
5.4.180.0080.03715.00
5.4.170.0020.04414.83
5.4.160.0060.04515.06
5.4.150.0060.03315.05
5.4.140.0050.03013.72
5.4.130.0020.03813.88
5.4.120.0120.03513.66
5.4.110.0050.04413.84
5.4.100.0100.02313.91
5.4.90.0070.04013.82
5.4.80.0020.04513.87
5.4.70.0050.04013.78
5.4.60.0070.03213.78
5.4.50.0040.02213.80
5.4.40.0090.02213.82
5.4.30.0050.02313.65
5.4.20.0090.01913.65
5.4.10.0040.02413.82
5.4.00.0030.02013.22
5.3.290.0090.03912.72
5.3.280.0040.03612.62
5.3.270.0060.04112.70
5.3.260.0050.02612.76
5.3.250.0080.04512.59
5.3.240.0050.03312.74
5.3.230.0120.03512.56
5.3.220.0060.04412.70
5.3.210.0060.04412.54
5.3.200.0030.03412.52
5.3.190.0090.03512.68
5.3.180.0050.02512.81
5.3.170.0060.03612.68
5.3.160.0070.02012.76
5.3.150.0070.02012.74
5.3.140.0080.01712.64
5.3.130.0080.02312.58
5.3.120.0060.02212.51
5.3.110.0080.01912.71
5.3.100.0030.02212.34
5.3.90.0090.01812.50
5.3.80.0060.02112.30
5.3.70.0060.02012.35
5.3.60.0040.02212.28
5.3.50.0060.01612.34
5.3.40.0070.01812.20
5.3.30.0050.02412.35
5.3.20.0060.02012.21
5.3.10.0060.03112.04
5.3.00.0020.02312.13
5.2.170.0020.02010.87
5.2.160.0040.01810.82
5.2.150.0050.01510.83
5.2.140.0080.02210.89
5.2.130.0040.01910.76
5.2.120.0110.01210.84
5.2.110.0080.01410.79
5.2.100.0090.03010.72
5.2.90.0030.01910.80
5.2.80.0080.02710.76
5.2.70.0050.03210.83
5.2.60.0070.01510.79
5.2.50.0020.02110.71
5.2.40.0080.01110.74
5.2.30.0040.01510.73
5.2.20.0050.01310.70
5.2.10.0050.01210.74
5.2.00.0060.01010.57
5.1.60.0070.01710.24
5.1.50.0000.01810.19
5.1.40.0050.01410.26
5.1.30.0030.01710.41
5.1.20.0060.01210.42
5.1.10.0020.01610.34
5.1.00.0050.01510.20
5.0.50.0020.0149.52
5.0.40.0070.0079.49
5.0.30.0000.0209.37
5.0.20.0060.0109.37
5.0.10.0010.0159.25
5.0.00.0050.0159.36
4.4.90.0050.0138.80
4.4.80.0050.0148.80
4.4.70.0030.0088.80
4.4.60.0000.0108.80
4.4.50.0020.0188.80
4.4.40.0030.0138.80
4.4.30.0020.0108.80
4.4.20.0030.0108.80
4.4.10.0000.0138.80
4.4.00.0040.0158.80
4.3.110.0020.0118.80
4.3.100.0030.0088.80
4.3.90.0020.0108.80
4.3.80.0020.0168.80
4.3.70.0060.0068.80
4.3.60.0020.0108.80
4.3.50.0000.0118.80
4.3.40.0030.0118.80
4.3.30.0000.0128.80
4.3.20.0020.0108.80
4.3.10.0040.0088.80
4.3.00.0040.0078.80

preferences:
69.28 ms | 400 KiB | 5 Q