3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "To be escaped: + - = && || > < ! ( ) { } [ ] ^ \" ~ * ? : \ / triple ||| and split '&<&'"; print_r( [ $string, LouisBarranqueiro($string), MikkoRantalainen($string), mickmackusa($string) ] ); function LouisBarranqueiro($string) { $regex = "/[\\+\\-\\=\\&\\|\\!\\(\\)\\{\\}\\[\\]\\^\\\"\\~\\*\\<\\>\\?\\:\\\\\\/]/"; $string = preg_replace_callback ($regex, function ($matches) { return "\\" . $matches[0]; }, $string); return $string; } function MikkoRantalainen($s) { static $replacements = array(); if (!$replacements) { # https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters $replacements = array( "\\" => "\\\\", # must be done first to not double encode later backslashes! "+" => "\\+", "-" => "\\-", "=" => "\\=", "&" => "\\&", "|" => "\\|", ">" => "", # cannot be safely encoded "<" => "", # cannot be safely encoded "!" => "\\!", "(" => "\\(", ")" => "\\)", "{" => "\\{", "}" => "\\}", "[" => "\\[", "]" => "\\]", "^" => "\\^", "\"" => "\\\"", "~" => "\\~", "*" => "\\*", "?" => "\\?", ":" => "\\:", "/" => "\\/", ); } return str_replace(array_keys($replacements), array_values($replacements), $s); } function mickmackusa($string) { return preg_replace( [ '_[<>]+_', // prevent hack where double-symbol is split by gt/lt symbol '_[-+=!(){}[\]^"~*?:\\/\\\\]|&(?=&)|\|(?=\|)_', ], [ '', '\\\\$0', ], $string ); }

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.5.00.0120.01120.13
8.4.150.0030.00014.05
8.4.140.0150.00617.96
8.4.130.0100.01317.64
8.4.120.0100.01220.35
8.4.110.0130.00719.15
8.4.100.0150.00617.75
8.4.90.0160.00520.61
8.4.80.0050.00320.64
8.4.70.0050.00319.13
8.4.60.0100.00320.66
8.4.50.0020.00820.54
8.4.40.0070.00719.79
8.4.30.0060.01020.57
8.4.20.0070.01319.12
8.4.10.0030.00619.85
8.3.270.0120.00716.57
8.3.260.0100.00916.75
8.3.250.0080.00818.98
8.3.240.0100.00916.76
8.3.230.0120.00716.80
8.3.220.0110.00618.71
8.3.210.0130.01016.66
8.3.200.0060.00416.65
8.3.190.0130.00517.18
8.3.180.0100.00616.82
8.3.170.0170.00319.12
8.3.160.0060.01216.67
8.3.150.0110.00719.05
8.3.140.0040.01416.66
8.3.130.0090.00018.61
8.3.120.0030.00620.71
8.3.110.0040.00420.94
8.3.100.0000.00918.45
8.3.90.0040.01226.77
8.3.80.0060.00319.36
8.3.70.0130.00618.68
8.3.60.0120.00316.62
8.3.50.0070.00716.73
8.3.40.0040.01119.04
8.3.30.0150.00019.11
8.3.20.0030.00524.18
8.3.10.0080.00024.66
8.3.00.0000.00926.16
8.2.290.0140.00517.32
8.2.280.0110.00818.89
8.2.270.0110.00717.20
8.2.260.0000.00819.00
8.2.250.0120.00316.76
8.2.240.0090.00017.24
8.2.230.0080.00022.58
8.2.220.0050.00524.06
8.2.210.0040.00426.77
8.2.200.0000.00918.88
8.2.190.0140.00718.56
8.2.180.0070.01125.92
8.2.170.0150.00619.00
8.2.160.0090.00622.96
8.2.150.0040.00425.66
8.2.140.0080.00024.66
8.2.130.0090.00026.16
8.2.120.0050.00321.04
8.2.110.0090.00020.32
8.2.100.0040.00818.03
8.2.90.0050.00318.00
8.2.80.0060.00619.06
8.2.70.0030.00917.75
8.2.60.0030.00618.05
8.2.50.0130.00018.07
8.2.40.0050.00318.15
8.2.30.0040.00418.23
8.2.20.0060.00318.21
8.2.10.0030.00521.38
8.2.00.0000.00819.50
8.1.330.0120.00616.30
8.1.320.0100.00623.95
8.1.310.0110.00716.79
8.1.300.0100.01018.36
8.1.290.0030.00630.84
8.1.280.0090.00625.92
8.1.270.0030.01424.66
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00618.92
8.1.230.0060.00617.85
8.1.220.0040.00417.79
8.1.210.0000.00818.77
8.1.200.0030.00617.47
8.1.190.0040.00817.47
8.1.180.0040.00418.10
8.1.170.0040.00418.91
8.1.160.0020.00518.97
8.1.150.0000.00718.99
8.1.140.0040.00418.98
8.1.130.0070.00020.30
8.1.120.0040.00417.57
8.1.110.0080.00017.59
8.1.100.0000.00717.64
8.1.90.0040.00417.63
8.1.80.0030.00717.61
8.1.70.0030.00317.49
8.1.60.0000.00717.73
8.1.50.0030.00517.70
8.1.40.0000.00817.59
8.1.30.0030.00617.82
8.1.20.0030.00517.79
8.1.10.0040.00417.79
8.1.00.0050.00317.69
8.0.300.0080.00018.77
8.0.290.0030.00617.00
8.0.280.0030.00618.55
8.0.270.0080.00018.17
8.0.260.0060.00018.42
8.0.250.0070.00017.12
8.0.240.0040.00417.02
8.0.230.0000.00716.99
8.0.220.0000.00717.09
8.0.210.0000.00816.98
8.0.200.0050.00317.01
8.0.190.0040.00417.16
8.0.180.0000.00816.98
8.0.170.0030.00616.96
8.0.160.0040.00417.01
8.0.150.0000.00816.99
8.0.140.0050.00317.05
8.0.130.0080.00013.52
8.0.120.0000.00916.92
8.0.110.0020.00517.11
8.0.100.0020.00517.09
8.0.90.0040.00417.10
8.0.80.0040.00517.10
8.0.70.0040.00617.05
8.0.60.0070.00317.04
8.0.50.0030.00617.09
8.0.30.0040.00517.06
8.0.20.0040.00517.14
8.0.10.0070.00317.22
8.0.00.0040.00517.21
7.4.330.0000.00615.55
7.4.320.0040.00416.81
7.4.300.0000.00616.82
7.4.290.0000.00716.74
7.4.280.0040.00416.70
7.4.270.0000.00716.79
7.4.260.0030.00313.57
7.4.250.0030.00616.76
7.4.240.0050.00216.90
7.4.230.0050.00116.81
7.4.220.0030.00516.80
7.4.210.0050.00516.84
7.4.200.0050.00416.85
7.4.190.0040.00516.79
7.4.180.0050.00616.87
7.4.160.0030.00616.80
7.4.150.0020.00716.78
7.4.140.0040.00416.77
7.4.130.0040.00516.78
7.4.120.0060.00316.75
7.4.110.0040.00516.75
7.4.100.0030.00516.87
7.4.90.0060.00216.70
7.4.80.0050.00416.75
7.4.70.0040.00516.76
7.4.60.0040.00516.79
7.4.50.0030.00516.65
7.4.40.0030.00616.73
7.4.30.0030.00616.76
7.4.20.0030.00616.63
7.4.10.0020.00716.68
7.4.00.0030.00616.63
7.3.330.0030.00316.41
7.3.320.0030.00313.37
7.3.310.0010.00616.46
7.3.300.0050.00216.49
7.3.290.0030.00616.59
7.3.280.0050.00416.51
7.3.270.0050.00316.51
7.3.260.0010.00816.51
7.3.250.0040.00516.47
7.3.240.0010.00816.50
7.3.230.0050.00416.45
7.3.220.0060.00316.41
7.3.210.0010.00816.42
7.3.200.0020.00716.42
7.3.190.0060.00416.49
7.3.180.0020.00816.41
7.3.170.0060.00516.41
7.3.160.0030.00616.42
7.3.150.0030.00616.45
7.3.140.0040.00516.51
7.3.130.0030.00616.42
7.3.120.0040.00516.50
7.3.110.0020.00716.36
7.3.100.0030.00516.37
7.3.90.0040.00516.78
7.3.80.0020.00716.54
7.3.70.0010.00816.62
7.3.60.0030.00616.61
7.3.50.0050.00516.62
7.3.40.0020.00616.64
7.3.30.0030.00516.65
7.3.20.0090.00517.53
7.3.10.0040.00617.52
7.3.00.0040.00617.45

preferences:
185.4 ms | 403 KiB | 5 Q