3v4l.org

run code in 300+ PHP versions simultaneously
<?php class str_replace_except_code { protected static $uniq; protected static $needle; protected static function replaceCB($matches){ return preg_replace("/".self::$uniq."/", self::$needle, $matches[0]); } /** * Replaces all instances of $needle found in $haystack with $replace except where $needle is between [CODE] tags. * @param string $haystack The string to search for instances of $needle * @param string $needle The string to find within $haystack * @param string $replace The replacement value * @return string $haystack with all instances of $needle replaced with $replace where not between [CODE] tags */ public static function go($haystack, $needle, $replace){ //generate a uniq string that shouldn't exist in the haystack self::$uniq = uniqid('UNIQ_', true); self::$needle = $needle; //replace all occurrences of the needle with the unique string $haystack = str_replace($needle, self::$uniq, $haystack); //replace all instances of the unique string between [code] tags with the original string $needle $haystack = preg_replace_callback("/\[CODE[^\]]*\].*?\[\/CODE\]/is", array('str_replace_except_code', 'replaceCB'), $haystack); //replace all remaining unique strings, which should be only those outside [code] tags with the replacement string $haystack = str_replace(self::$uniq, $replace, $haystack); //return the original string with the correct replacements return $haystack; } } $haystack =<<<POST hello /r/n im showing some code /r/n [CODE=HTML] <html> /r/n /r/n </html> [/CODE]/r/n thanks POST; $needle = "/r/n"; $replace= "<br>"; echo '<h1>Before replace:</h1>'; echo '<pre>'.htmlentities($haystack).'</pre>'; echo '<hr>'; echo '<h1>After replace:</h1>'; echo '<pre>'.htmlentities(str_replace_except_code::go($haystack, $needle, $replace)).'</pre>';

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)
7.4.10.0060.01215.10
7.4.00.0030.01315.25
7.3.130.0000.01615.10
7.3.120.0060.00714.87
7.3.110.0100.00714.80
7.3.100.0110.00515.08
7.3.90.0070.00415.05
7.3.80.0060.00415.08
7.3.70.0050.01014.90
7.3.60.0060.00814.97
7.3.50.0050.00714.89
7.3.40.0090.00314.89
7.3.30.0070.00814.76
7.3.20.0060.00816.93
7.3.10.0070.00716.68
7.3.00.0040.00516.73
7.2.260.0030.01315.53
7.2.250.0080.01015.35
7.2.240.0110.00615.36
7.2.230.0080.00615.04
7.2.220.0070.00715.06
7.2.210.0070.00615.19
7.2.200.0040.01115.28
7.2.190.0070.00915.27
7.2.180.0080.00815.16
7.2.170.0000.01215.15
7.2.160.0070.00815.13
7.2.150.0070.00416.98
7.2.140.0020.01117.15
7.2.130.0040.01017.18
7.2.120.0020.01317.11
7.2.110.0040.00817.16
7.2.100.0030.01017.09
7.2.90.0050.00817.04
7.2.80.0020.01517.13
7.2.70.0100.00316.92
7.2.60.0060.01016.85
7.2.50.0080.00816.98
7.2.40.0030.01017.18
7.2.30.0080.00517.01
7.2.20.0070.00517.27
7.2.10.0040.01117.12
7.2.00.0070.00917.01
7.1.330.0060.00815.86
7.1.320.0050.00915.84
7.1.310.0040.01115.87
7.1.300.0060.00615.70
7.1.290.0070.00715.91
7.1.280.0030.00815.95
7.1.270.0070.00715.95
7.1.260.0040.00815.96
7.1.250.0080.00816.08
7.1.240.0080.00716.04
7.1.230.0040.00915.91
7.1.220.0060.00915.94
7.1.210.0100.00315.86
7.1.200.0080.00515.94
7.1.190.0090.00315.87
7.1.180.0070.00715.88
7.1.170.0090.00515.80
7.1.160.0080.00415.98
7.1.150.0050.00816.12
7.1.140.0040.01015.82
7.1.130.0080.00516.11
7.1.120.0090.00515.77
7.1.110.0060.00515.96
7.1.100.0040.00916.05
7.1.90.0040.00916.04
7.1.80.0000.01315.91
7.1.70.0070.00716.33
7.1.60.0070.01017.05
7.1.50.0030.01416.25
7.1.40.0020.01015.74
7.1.30.0060.01016.01
7.1.20.0050.01116.03
7.1.10.0030.01015.97
7.1.00.0030.03318.06
7.0.330.0060.00815.64
7.0.320.0090.00315.19
7.0.310.0060.00615.52
7.0.300.0060.00315.27
7.0.290.0020.01115.39
7.0.280.0080.00615.54
7.0.270.0050.00815.52
7.0.260.0080.00315.37
7.0.250.0070.00315.44
7.0.240.0090.00515.45
7.0.230.0000.01215.47
7.0.220.0070.00815.45
7.0.210.0060.00615.43
7.0.200.0080.00416.12
7.0.190.0070.00715.34
7.0.180.0050.00515.64
7.0.170.0060.00815.41
7.0.160.0060.00615.38
7.0.150.0040.00515.57
7.0.140.0060.00815.50
7.0.130.0060.00515.35
7.0.120.0050.00915.42
7.0.110.0060.00815.30
7.0.100.0070.02316.98
7.0.90.0040.03116.91
7.0.80.0100.03016.93
7.0.70.0030.02716.97
7.0.60.0110.02916.87
7.0.50.0150.02017.01
7.0.40.0040.02915.77
7.0.30.0080.02715.62
7.0.20.0050.03415.72
7.0.10.0030.03515.45
7.0.00.0050.03115.64
5.6.400.0040.00914.53
5.6.390.0070.00914.69
5.6.380.0050.00614.46
5.6.370.0060.00914.38
5.6.360.0020.01314.51
5.6.350.0040.00814.62
5.6.340.0070.00614.31
5.6.330.0070.00714.38
5.6.320.0070.00814.62
5.6.310.0050.01014.51
5.6.300.0120.00414.35
5.6.290.0130.00214.41
5.6.280.0050.00514.29
5.6.270.0030.01014.34
5.6.260.0050.00914.35
5.6.250.0040.03216.48
5.6.240.0070.02516.39
5.6.230.0120.02716.53
5.6.220.0040.02816.59
5.6.210.0080.02416.37
5.6.200.0040.03416.52
5.6.190.0040.03516.54
5.6.180.0070.02316.63
5.6.170.0040.03516.54
5.6.160.0070.02316.58
5.6.150.0080.02716.74
5.6.140.0090.02816.57
5.6.130.0080.02716.65
5.6.120.0090.02016.69
5.6.110.0070.02716.55
5.6.100.0050.01816.63
5.6.90.0070.03316.75
5.6.80.0080.02716.34
5.6.70.0060.02816.29
5.6.60.0060.03116.22
5.6.50.0050.02816.23
5.6.40.0090.02616.32
5.6.30.0030.02016.39
5.6.20.0060.02616.27
5.6.10.0070.02916.25
5.6.00.0100.02816.43
5.5.380.0060.03016.46
5.5.370.0070.02216.45
5.5.360.0070.02216.27
5.5.350.0080.02616.48
5.5.340.0030.03516.71
5.5.330.0060.02016.54
5.5.320.0070.01516.47
5.5.310.0050.02016.56
5.5.300.0030.03416.63
5.5.290.0050.02616.54
5.5.280.0010.02716.46
5.5.270.0160.01516.47
5.5.260.0080.02716.52
5.5.250.0040.01616.22
5.5.240.0090.02916.31
5.5.230.0040.02516.20
5.5.220.0080.03016.24
5.5.210.0060.03116.15
5.5.200.0060.02716.35
5.5.190.0080.02616.31
5.5.180.0050.02516.39
5.5.170.0050.00614.38
5.5.160.0030.03516.20
5.5.150.0110.02816.17
5.5.140.0030.02016.26
5.5.130.0060.02016.16
5.5.120.0060.03016.30
5.5.110.0040.02416.30
5.5.100.0050.02016.21
5.5.90.0080.02716.19
5.5.80.0080.02816.24
5.5.70.0060.02716.23
5.5.60.0060.02116.38
5.5.50.0040.03116.24
5.5.40.0050.03316.25
5.5.30.0040.02316.19
5.5.20.0080.01916.02
5.5.10.0040.03116.17
5.5.00.0050.02316.06
5.4.450.0060.02014.64
5.4.440.0090.02614.58
5.4.430.0060.02614.58
5.4.420.0040.03214.70
5.4.410.0090.02914.61
5.4.400.0040.01614.47
5.4.390.0100.02614.55
5.4.380.0070.01314.52
5.4.370.0060.02414.54
5.4.360.0030.03014.57
5.4.350.0040.02114.55
5.4.340.0040.02014.48
5.4.330.0030.00512.26
5.4.320.0050.01514.58
5.4.310.0040.02314.56
5.4.300.0030.02714.47
5.4.290.0030.02414.52
5.4.280.0040.02814.58
5.4.270.0110.02014.57
5.4.260.0000.02714.58
5.4.250.0080.01914.55
5.4.240.0020.03314.52
5.4.230.0090.01714.52
5.4.220.0070.02214.55
5.4.210.0090.02414.52
5.4.200.0070.02514.54
5.4.190.0030.03214.45
5.4.180.0080.02614.51
5.4.170.0070.03214.48
5.4.160.0030.01914.53
5.4.150.0040.01914.46
5.4.140.0050.03113.57
5.4.130.0060.02513.61
5.4.120.0100.02213.63
5.4.110.0030.02813.65
5.4.100.0060.02613.70
5.4.90.0060.02113.68
5.4.80.0020.03313.63
5.4.70.0080.02113.64
5.4.60.0030.03113.64
5.4.50.0070.02513.67
5.4.40.0040.03013.67
5.4.30.0050.03113.64
5.4.20.0010.02413.63
5.4.10.0050.03013.65
5.4.00.0070.02013.49
5.3.290.0030.08014.79
5.3.280.0130.06714.71
5.3.270.0230.03014.75
5.3.260.0000.07714.72
5.3.250.0070.06714.73
5.3.240.0070.04314.72
5.3.230.0070.04714.54
5.3.220.0100.07714.69
5.3.210.0200.06714.56
5.3.200.0030.05314.68
5.3.190.0070.04714.63
5.3.180.0030.04714.69
5.3.170.0100.06014.46
5.3.160.0000.07714.63
5.3.150.0030.08314.69
5.3.140.0070.07714.59
5.3.130.0070.06314.49
5.3.120.0070.07314.62
5.3.110.0070.04314.55
5.3.100.0030.07313.98
5.3.90.0100.06714.01
5.3.80.0100.07014.14
5.3.70.0030.07714.02
5.3.60.0070.07713.93
5.3.50.0030.07313.91
5.3.40.0070.07013.94
5.3.30.0100.06313.89
5.3.20.0100.07013.62
5.3.10.0130.06013.66
5.3.00.0130.07313.78
5.2.170.0000.06011.21
5.2.160.0000.03311.18
5.2.150.0070.06311.21
5.2.140.0100.03311.25
5.2.130.0070.06010.97
5.2.120.0130.04311.21
5.2.110.0100.04011.13
5.2.100.0000.06311.22
5.2.90.0000.07711.12
5.2.80.0070.06011.12
5.2.70.0030.05311.19
5.2.60.0000.05711.13
5.2.50.0030.06311.11
5.2.40.0070.05311.02
5.2.30.0000.04010.89
5.2.20.0030.03311.07
5.2.10.0000.03310.88
5.2.00.0130.01710.86
5.1.60.0000.02710.11
5.1.50.0000.02710.13
5.1.40.0030.02310.06
5.1.30.0000.02710.41
5.1.20.0000.03010.34
5.1.10.0070.02310.22
5.1.00.0030.02710.20
5.0.50.0000.0239.81
5.0.40.0000.0279.81
5.0.30.0000.0279.81
5.0.20.0030.0139.81
5.0.10.0000.0209.81
5.0.00.0000.0309.81
4.4.90.0030.0309.81
4.4.80.0030.0379.81
4.4.70.0000.0209.81
4.4.60.0000.0279.81
4.4.50.0000.0209.81
4.4.40.0000.0279.81
4.4.30.0000.0209.81
4.4.20.0000.0179.81
4.4.10.0030.0139.81
4.4.00.0000.0279.81
4.3.110.0000.0179.81
4.3.100.0000.0139.81
4.3.90.0000.0179.81
4.3.80.0030.0309.81
4.3.70.0030.0139.81
4.3.60.0000.0139.81
4.3.50.0030.0139.81
4.3.40.0000.0209.81
4.3.30.0000.0139.81
4.3.20.0000.0179.81
4.3.10.0000.0179.81
4.3.00.0030.0109.81

preferences:
41.38 ms | 400 KiB | 5 Q