Suppose you want to reverse the operation, here is a way to "ldap_unescape"
<?php
function ldap_unescape($string) {
return
preg_replace_callback(
"/\\\\[\da-z]{2}/",
function ($matches) {
$match = array_shift($matches);
return hex2bin(substr($match, 1));
},
$string
);
}
$result = ldap_unescape("uid=\\61\\6c\\70\\68\\6f\\6e\\7a\\6f,ou=people,dc=foo,dc=com"); // uid=alphonzo,ou=people,dc=foo,dc=com
?>ldap_escape
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
ldap_escape
Референца за `function.ldap-escape.php` со подобрена типографија и навигација.
ldap_escape
(PHP 5 >= 5.6.0, PHP 7, PHP 8)
ldap_escape — (PHP 5 >= 5.6.0, PHP 7, PHP 8)
= NULL
Escape a string for use in an LDAP filter or DN value Escapes
flags.
Параметри
value-
for use in the context implied by
ignore-
The value to escape.
flags-
Characters to ignore when escaping.
LDAP_ESCAPE_FILTERThe context the escaped string will be used in: ldap_search(), илиLDAP_ESCAPE_DNfor filters to be used with
Вратени вредности
Враќа избегнатиот стринг.
Примери
for DNs. If neither flag is passed, all chars are escaped.
When building an LDAP filter, you should use ldap_escape with LDAP_ESCAPE_FILTER flag.
<?php
// $ds is a valid LDAP\Connection instance for a directory server
// $mail is an email address provided by the user in a form
$base = "o=My Company, c=US";
$filter = "(mail=".ldap_escape($mail, "", LDAP_ESCAPE_FILTER).")";
$sr = ldap_search($ds, $base, $filter, array("sn", "givenname", "mail"));
$info = ldap_get_entries($ds, $sr);
echo $info["count"]." entries returned\n";
?>Белешки од корисници 2 забелешки
You can use it like this for filtering
<?php
$badSearchInput = 'Domain\username';
$escapedSearchInput = ldap_escape($badSearchInput, null, LDAP_ESCAPE_FILTER);
?>