3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('ldap_escape')) { echo "defining\n"; define('LDAP_ESCAPE_FILTER', 0x01); define('LDAP_ESCAPE_DN', 0x02); /** * @param string $subject The subject string * @param string $ignore Set of characters to leave untouched * @param int $flags Any combination of LDAP_ESCAPE_* flags to indicate the * set(s) of characters to escape. * @return string */ function ldap_escape($subject, $ignore = '', $flags = 0) { static $charMaps = array( LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"), LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'), ); // Pre-process the char maps on first call if (!isset($charMaps[0])) { $charMaps[0] = array(); for ($i = 0; $i < 256; $i++) { $charMaps[0][chr($i)] = sprintf('\\%02x', ord($i));; } for ($i = 0, $l = count($charMaps[LDAP_ESCAPE_FILTER]); $i < $l; $i++) { $chr = $charMaps[LDAP_ESCAPE_FILTER][$i]; unset($charMaps[LDAP_ESCAPE_FILTER][$i]); $charMaps[LDAP_ESCAPE_FILTER][$chr] = $charMaps[0][$chr]; } for ($i = 0, $l = count($charMaps[LDAP_ESCAPE_DN]); $i < $l; $i++) { $chr = $charMaps[LDAP_ESCAPE_DN][$i]; unset($charMaps[LDAP_ESCAPE_DN][$i]); $charMaps[LDAP_ESCAPE_DN][$chr] = $charMaps[0][$chr]; } } // Create the base char map to escape $flags = (int)$flags; $charMap = array(); if ($flags & LDAP_ESCAPE_FILTER) { $charMap += $charMaps[LDAP_ESCAPE_FILTER]; } if ($flags & LDAP_ESCAPE_DN) { $charMap += $charMaps[LDAP_ESCAPE_DN]; } if (!$charList) { $charMap = $charMaps[0]; } // Remove any chars to ignore from the list $ignore = (string)$ignore; for ($i = 0, $l = strlen($ignore); $i < $l; $i++) { unset($charMap[$ignore[$i]]); } // Do the main replacement $result = strtr($subject, $charMap); // Encode leading/trailing spaces if LDAP_ESCAPE_DN is passed if ($flags & LDAP_ESCAPE_DN) { if ($result[0] === ' ') { $result = '\\20' . substr($result, 1); } if ($result[strlen($result) - 1] === ' ') { $result = substr($result, 0, -1) . '\\20'; } } return $result; } } $subject = "(one \\f #)" echo ldap_escape($subject) . "\n"; echo ldap_escape($subject, '', LDAP_ESCAPE_DN) . "\n"; echo ldap_escape($subject, '', LDAP_ESCAPE_FILTER) . "\n"; echo ldap_escape($subject, '#', LDAP_ESCAPE_DN) . "\n"; echo ldap_escape($subject, '(', LDAP_ESCAPE_FILTER) . "\n";

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)
5.4.340.0070.03312.04
5.4.320.0060.04412.54
5.4.310.0070.03712.54
5.4.300.0090.04312.54
5.4.290.0090.04812.53
5.4.280.0060.03912.43
5.4.270.0060.03612.43
5.4.260.0070.03612.43
5.4.250.0080.04112.43
5.4.240.0060.03812.43
5.4.230.0040.04012.42
5.4.220.0030.04412.42
5.4.210.0100.04912.42
5.4.200.0070.04312.42
5.4.190.0070.03712.41
5.4.180.0080.04112.42
5.4.170.0090.03912.43
5.4.160.0080.03312.42
5.4.150.0070.03612.41
5.4.140.0050.04012.11
5.4.130.0070.03512.09
5.4.120.0070.03712.05
5.4.110.0100.03612.05
5.4.100.0070.04012.05
5.4.90.0050.03812.05
5.4.80.0070.03712.05
5.4.70.0070.03412.05
5.4.60.0050.03512.04
5.4.50.0040.03912.05
5.4.40.0050.04112.03
5.4.30.0100.03912.03
5.4.20.0030.04412.03
5.4.10.0100.03812.03
5.4.00.0080.04211.52
5.3.290.0040.04612.80
5.3.280.0120.03812.71
5.3.270.0090.04412.72
5.3.260.0070.04412.72
5.3.250.0080.03912.72
5.3.240.0070.04012.72
5.3.230.0090.04012.70
5.3.220.0070.03712.68
5.3.210.0090.04312.68
5.3.200.0060.03612.68
5.3.190.0090.04412.68
5.3.180.0100.03812.68
5.3.170.0060.03712.68
5.3.160.0060.03712.67
5.3.150.0090.03412.68
5.3.140.0060.03712.66
5.3.130.0100.03912.66
5.3.120.0090.03512.66
5.3.110.0060.04112.66
5.3.100.0070.04012.14
5.3.90.0080.03512.13
5.3.80.0030.04012.12
5.3.70.0080.04012.12
5.3.60.0050.04112.10
5.3.50.0070.03612.05
5.3.40.0110.03212.05
5.3.30.0040.03712.01
5.3.20.0070.04111.80
5.3.10.0110.03611.76
5.3.00.0100.03711.74
5.2.170.0040.0379.25
5.2.160.0080.0299.25
5.2.150.0050.0389.25
5.2.140.0050.0309.25
5.2.130.0060.0299.21
5.2.120.0060.0289.20
5.2.110.0050.0289.22
5.2.100.0040.0299.20
5.2.90.0080.0339.21
5.2.80.0050.0299.20
5.2.70.0050.0309.20
5.2.60.0030.0319.16
5.2.50.0070.0279.13
5.2.40.0020.0319.11
5.2.30.0040.0309.08
5.2.20.0030.0329.07
5.2.10.0060.0298.97
5.2.00.0050.0348.84
5.1.60.0040.0248.12
5.1.50.0050.0258.12
5.1.40.0060.0268.10
5.1.30.0060.0328.45
5.1.20.0040.0278.47
5.1.10.0070.0258.19
5.1.00.0030.0328.19
5.0.50.0040.0256.68
5.0.40.0050.0206.54
5.0.30.0040.0346.36
5.0.20.0040.0216.31
5.0.10.0040.0226.30
5.0.00.0040.0306.29
4.4.90.0000.0184.78
4.4.80.0070.0154.75
4.4.70.0050.0134.75
4.4.60.0010.0174.76
4.4.50.0040.0144.77
4.4.40.0030.0254.71
4.4.30.0030.0154.76
4.4.20.0040.0184.84
4.4.10.0030.0194.85
4.4.00.0040.0254.76
4.3.110.0090.0134.67
4.3.100.0060.0154.67
4.3.90.0010.0204.64
4.3.80.0040.0244.58
4.3.70.0040.0144.63
4.3.60.0010.0194.63
4.3.50.0040.0154.63
4.3.40.0020.0254.54
4.3.30.0060.0153.34
4.3.20.0030.0163.31
4.3.10.0020.0173.27
4.3.00.0200.0206.89

preferences:
144.19 ms | 1394 KiB | 7 Q