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 . '/', ' ', $match[0][0]), $search); $haystack = substr_replace($haystack, $replacement[$found], $match[0][1], $match[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.70.0130.00716.63
8.3.60.0130.00618.55
8.3.50.0100.00821.27
8.3.40.0140.00418.88
8.3.30.0070.00720.38
8.3.20.0040.00420.33
8.3.10.0040.00421.93
8.3.00.0000.00822.34
8.2.180.0150.00616.75
8.2.170.0150.00022.96
8.2.160.0140.00022.24
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0000.00920.93
8.2.110.0060.00322.15
8.2.100.0060.00618.13
8.2.90.0030.00519.13
8.2.80.0030.00519.25
8.2.70.0050.00317.88
8.2.60.0030.00517.80
8.2.50.0080.00018.07
8.2.40.0040.00420.01
8.2.30.0040.00419.61
8.2.20.0040.00417.89
8.2.10.0080.00017.86
8.2.00.0030.00517.99
8.1.280.0140.00425.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00323.92
8.1.230.0080.00419.23
8.1.220.0090.00017.89
8.1.210.0050.00318.77
8.1.200.0080.00417.73
8.1.190.0000.00817.43
8.1.180.0030.00619.26
8.1.170.0040.00418.77
8.1.160.0070.00318.94
8.1.150.0070.00018.80
8.1.140.0000.00717.68
8.1.130.0000.00717.87
8.1.120.0000.00717.65
8.1.110.0040.00417.59
8.1.100.0000.00817.55
8.1.90.0070.00017.54
8.1.80.0070.00017.61
8.1.70.0030.00317.54
8.1.60.0080.00017.79
8.1.50.0000.00817.71
8.1.40.0050.00517.63
8.1.30.0040.00417.81
8.1.20.0030.00617.87
8.1.10.0050.00317.72
8.1.00.0030.00617.66
8.0.300.0060.00318.77
8.0.290.0000.00817.30
8.0.280.0000.00818.50
8.0.270.0080.00017.30
8.0.260.0030.00317.12
8.0.250.0030.00317.07
8.0.240.0040.00417.11
8.0.230.0000.00817.21
8.0.220.0000.00717.02
8.0.210.0070.00017.00
8.0.200.0070.00017.06
8.0.190.0080.00017.06
8.0.180.0040.00417.19
8.0.170.0040.00417.22
8.0.160.0000.00717.26
8.0.150.0040.00417.16
8.0.140.0050.00216.97
8.0.130.0060.00013.61
8.0.120.0040.00416.97
8.0.110.0040.00417.11
8.0.100.0040.00417.16
8.0.90.0000.00716.95
8.0.80.0090.00617.06
8.0.70.0000.00717.14
8.0.60.0070.00016.93
8.0.50.0000.00717.05
8.0.30.0140.00517.29
8.0.20.0120.00717.40
8.0.10.0050.00217.15
8.0.00.0140.00416.90
7.4.330.0000.00515.00
7.4.320.0030.00316.85
7.4.300.0000.00616.75
7.4.290.0030.00316.86
7.4.280.0040.00416.88
7.4.270.0040.00416.61
7.4.260.0060.00313.54
7.4.250.0030.00616.84
7.4.240.0000.00816.73
7.4.230.0050.00316.64
7.4.220.0110.00716.80
7.4.210.0120.00616.84
7.4.200.0000.00716.85
7.4.190.0000.00716.70
7.4.160.0070.01116.77
7.4.150.0040.01317.40
7.4.140.0150.00217.86
7.4.130.0130.00516.82
7.4.120.0080.01016.75
7.4.110.0090.00916.71
7.4.100.0070.01016.93
7.4.90.0060.01216.83
7.4.80.0110.00719.39
7.4.70.0140.00416.80
7.4.60.0100.00716.81
7.4.50.0030.00316.91
7.4.40.0100.00622.77
7.4.30.0100.01316.63
7.4.10.0070.01115.41
7.4.00.0080.01015.14
7.3.330.0030.00313.71
7.3.320.0030.00313.41
7.3.310.0040.00416.65
7.3.300.0000.00716.52
7.3.290.0030.01616.58
7.3.280.0050.01416.60
7.3.270.0100.00717.40
7.3.260.0070.01116.68
7.3.250.0050.01916.87
7.3.240.0130.00416.62
7.3.230.0100.00816.70
7.3.210.0040.01316.56
7.3.200.0130.00519.39
7.3.190.0120.00916.73
7.3.180.0030.01216.49
7.3.170.0120.00416.62
7.3.160.0080.00816.73
7.3.130.0060.01315.22
7.3.120.0050.01215.06
7.3.110.0030.01315.17
7.3.100.0100.00315.16
7.3.90.0030.00914.88
7.3.80.0030.00615.06
7.3.70.0080.00415.05
7.3.60.0080.00315.17
7.3.50.0070.00315.10
7.3.40.0090.00615.01
7.3.30.0110.00614.97
7.3.20.0080.00816.65
7.3.10.0040.01116.92
7.3.00.0130.00616.63
7.2.330.0090.00916.88
7.2.320.0160.00316.91
7.2.310.0140.01016.87
7.2.300.0110.00516.87
7.2.290.0090.00916.98
7.2.260.0120.00615.47
7.2.250.0090.00915.07
7.2.240.0070.01115.05
7.2.230.0070.01115.29
7.2.220.0000.01215.32
7.2.210.0030.00615.29
7.2.200.0070.00415.27
7.2.190.0000.01215.25
7.2.180.0090.00315.36
7.2.170.0070.01015.04
7.2.160.0030.01415.36
7.2.150.0040.00817.18
7.2.140.0030.01016.95
7.2.130.0070.01117.28
7.2.120.0090.00317.32
7.2.110.0000.01617.34
7.2.100.0100.00717.06
7.2.90.0000.01016.79
7.2.80.0040.00817.18
7.2.70.0000.01817.22
7.2.60.0040.01417.13
7.2.50.0040.01117.13
7.2.40.0030.00616.94
7.2.30.0040.01117.34
7.2.20.0000.01417.32
7.2.10.0030.00617.14
7.2.00.0050.00918.37
7.1.330.0070.01015.89
7.1.320.0060.01016.28
7.1.310.0030.01015.89
7.1.300.0000.00815.93
7.1.290.0070.00715.96
7.1.280.0000.01615.74
7.1.270.0070.00415.93
7.1.260.0070.01116.18
7.1.250.0030.01415.66
7.1.240.0030.01016.03
7.1.230.0070.00716.22
7.1.220.0030.01015.94
7.1.210.0080.00816.16
7.1.200.0040.00915.96
7.1.190.0070.00715.77
7.1.180.0000.01315.83
7.1.170.0000.01315.95
7.1.160.0040.00415.99
7.1.150.0000.01216.04
7.1.140.0040.01115.93
7.1.130.0000.00815.90
7.1.120.0030.01316.02
7.1.110.0090.00616.12
7.1.100.0040.00917.21
7.1.90.0060.00816.15
7.1.80.0060.00316.14
7.1.70.0070.00516.76
7.1.60.0050.01016.73
7.1.50.0030.01116.62
7.1.40.0070.00415.76
7.1.30.0040.01115.79
7.1.20.0000.00916.09
7.1.10.0060.00915.62
7.1.00.0020.03319.22
7.0.330.0100.01015.52
7.0.320.0080.00415.54
7.0.310.0030.01015.61
7.0.300.0080.00015.71
7.0.290.0060.00915.61
7.0.280.0030.00815.61
7.0.270.0090.00015.59
7.0.260.0070.00715.72
7.0.250.0030.01315.88
7.0.240.0000.01115.70
7.0.230.0080.00515.79
7.0.220.0100.00315.22
7.0.210.0060.00915.61
7.0.200.0020.00816.29
7.0.190.0050.00315.68
7.0.180.0070.00715.23
7.0.170.0040.01115.60
7.0.160.0080.00615.72
7.0.150.0030.01315.75
7.0.140.0070.04118.89
7.0.130.0070.00815.37
7.0.120.0030.01015.77
7.0.110.0070.00715.71
7.0.100.0070.00315.54
7.0.90.0070.00315.74
7.0.80.0100.02417.81
7.0.70.0090.04317.77
7.0.60.0170.04217.72
7.0.50.0170.03318.17
7.0.40.0080.02816.88
7.0.30.0080.04316.96
7.0.20.0090.04616.80
7.0.10.0050.02916.90
7.0.00.0080.03516.76
5.6.400.0030.01014.47
5.6.390.0000.01714.51
5.6.380.0070.00714.32
5.6.370.0030.01014.41
5.6.360.0080.00014.81
5.6.350.0030.00614.61
5.6.340.0000.01414.23
5.6.330.0000.01314.75
5.6.320.0000.00914.77
5.6.310.0110.00614.46
5.6.300.0090.00614.46
5.6.290.0000.00914.10
5.6.280.0000.04117.84
5.6.270.0090.00614.43
5.6.260.0110.00014.38
5.6.250.0030.00714.39
5.6.240.0040.00814.78
5.6.230.0100.04317.66
5.6.220.0100.03717.64
5.6.210.0080.03117.48
5.6.200.0080.02217.73
5.6.190.0100.03817.78
5.6.180.0050.04717.84
5.6.170.0070.03817.83
5.6.160.0100.03817.62
5.6.150.0100.03317.78
5.6.140.0030.02817.71
5.6.130.0030.02917.76
5.6.120.0080.03017.80
5.6.110.0160.02517.72
5.6.100.0090.04317.71
5.6.90.0090.02517.92
5.6.80.0040.03917.56
5.6.70.0030.04517.40
5.6.60.0060.04317.32
5.6.50.0070.04017.36
5.6.40.0060.04617.35
5.6.30.0090.03417.40
5.6.20.0030.02717.49
5.6.10.0050.02717.34
5.6.00.0080.02317.44
5.5.380.0070.00714.61
5.5.370.0020.03117.58
5.5.360.0020.04517.46
5.5.350.0060.03217.44
5.5.340.0080.02617.69
5.5.330.0050.04017.58
5.5.320.0030.04717.65
5.5.310.0070.03817.66
5.5.300.0020.02917.54
5.5.290.0120.04217.61
5.5.280.0040.03517.69
5.5.270.0050.03217.55
5.5.260.0030.04317.75
5.5.250.0050.04617.46
5.5.240.0060.04217.27
5.5.230.0030.04117.38
5.5.220.0030.04317.30
5.5.210.0030.04217.28
5.5.200.0030.03317.40
5.5.190.0120.03517.10
5.5.180.0090.04117.30
5.5.170.0000.01414.52
5.5.160.0050.02917.16
5.5.150.0020.03417.36
5.5.140.0050.04717.21
5.5.130.0110.03817.24
5.5.120.0050.02817.15
5.5.110.0050.02917.34
5.5.100.0070.02817.24
5.5.90.0070.02317.24
5.5.80.0050.04317.10
5.5.70.0100.03317.20
5.5.60.0030.02617.12
5.5.50.0100.03817.25
5.5.40.0120.03417.16
5.5.30.0100.02617.29
5.5.20.0070.03517.26
5.5.10.0080.03617.34
5.5.00.0080.03917.02
5.4.450.0070.02415.39
5.4.440.0050.02515.32
5.4.430.0150.03515.32
5.4.420.0060.03815.21
5.4.410.0020.03015.18
5.4.400.0070.03515.28
5.4.390.0050.04515.11
5.4.380.0080.02315.08
5.4.370.0030.03915.06
5.4.360.0060.04015.24
5.4.350.0070.04215.11
5.4.340.0040.02715.34
5.4.330.0100.00311.44
5.4.320.0090.02815.19
5.4.310.0100.03215.00
5.4.300.0080.03815.14
5.4.290.0110.02215.16
5.4.280.0070.02515.16
5.4.270.0050.04315.13
5.4.260.0090.02415.27
5.4.250.0030.02715.19
5.4.240.0050.02615.18
5.4.230.0040.02415.16
5.4.220.0030.03615.13
5.4.210.0120.03215.14
5.4.200.0070.02315.10
5.4.190.0120.03515.28
5.4.180.0070.02015.07
5.4.170.0050.04315.14
5.4.160.0090.01815.22
5.4.150.0080.02015.22
5.4.140.0050.04214.03
5.4.130.0020.04213.81
5.4.120.0030.03813.91
5.4.110.0070.02313.80
5.4.100.0090.03613.95
5.4.90.0000.02713.79
5.4.80.0060.02313.96
5.4.70.0030.03913.82
5.4.60.0050.03213.82
5.4.50.0050.04313.79
5.4.40.0030.02813.91
5.4.30.0020.04613.76
5.4.20.0080.03313.92
5.4.10.0050.02313.84
5.4.00.0000.04413.60
5.3.290.0060.04512.97
5.3.280.0100.03212.94
5.3.270.0070.03712.88
5.3.260.0070.02812.86
5.3.250.0020.02512.87
5.3.240.0050.03512.86
5.3.230.0090.04112.81
5.3.220.0070.03712.84
5.3.210.0090.03112.84
5.3.200.0040.02712.85
5.3.190.0120.03312.86
5.3.180.0060.03112.82
5.3.170.0070.02012.82
5.3.160.0090.04012.82
5.3.150.0120.03512.88
5.3.140.0020.04312.89
5.3.130.0070.03812.81
5.3.120.0070.02712.88
5.3.110.0030.02412.83
5.3.100.0020.03112.65
5.3.90.0030.02012.62
5.3.80.0050.02512.57
5.3.70.0030.02612.61
5.3.60.0050.04212.59
5.3.50.0060.02212.53
5.3.40.0050.03612.59
5.3.30.0030.02312.56
5.3.20.0070.02012.38
5.3.10.0060.03412.43
5.3.00.0070.02712.42
5.2.170.0130.05011.75
5.2.160.0030.03311.75
5.2.150.0070.03011.75
5.2.140.0030.03311.75
5.2.130.0000.05711.75
5.2.120.0000.03311.75
5.2.110.0030.06011.75
5.2.100.0070.05711.75
5.2.90.0030.04011.75
5.2.80.0030.06711.75
5.2.70.0030.05011.75
5.2.60.0000.07011.75
5.2.50.0000.03311.75
5.2.40.0070.03011.75
5.2.30.0030.03011.75
5.2.20.0030.03011.75
5.2.10.0070.04011.75
5.2.00.0030.05711.75
5.1.60.0000.03011.75
5.1.50.0030.05011.75
5.1.40.0070.02311.75
5.1.30.0000.05311.75
5.1.20.0100.03711.75
5.1.10.0030.03011.75
5.1.00.0000.04011.75
5.0.50.0030.03711.75
5.0.40.0030.02311.75
5.0.30.0030.05711.75
5.0.20.0030.02311.75
5.0.10.0030.04011.75
5.0.00.0000.03711.75
4.4.90.0100.02711.75
4.4.80.0030.01311.75
4.4.70.0030.02711.75
4.4.60.0030.01311.75
4.4.50.0000.03011.75
4.4.40.0000.02711.75
4.4.30.0000.03711.75
4.4.20.0030.03311.75
4.4.10.0030.03311.75
4.4.00.0030.04311.75
4.3.110.0070.03011.75
4.3.100.0070.03011.75
4.3.90.0000.02011.75
4.3.80.0030.02711.75
4.3.70.0070.02311.75
4.3.60.0030.03011.75
4.3.50.0000.03011.75
4.3.40.0000.03311.75
4.3.30.0030.03311.75
4.3.20.0000.01711.75
4.3.10.0000.02011.75
4.3.00.0000.03311.75

preferences:
49.39 ms | 401 KiB | 5 Q