note 90158 modified in function.ldap-search by felipe
| From: | felipe@php.net | Date: | Sun, 12 Apr 2009 20:01:05 +0000 |
| Subject: | note 90158 modified in function.ldap-search by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153125@lists.php.net to get a copy of this message | ||
A better ldap_escape, if you don't need nested filters such as those in the Pear package.
Escapes for both filters and distinguished names.
<?php
function ldap_escape($str, $for_dn = false)
{
// see:
// RFC2254
// http://msdn.microsoft.com/en-us/library/ms675768(VS.85).aspx
// http://www-03.ibm.com/systems/i/software/ldap/underdn.html
if ($for_dn)
$metaChars = array(',','=', '+',
'<','>',';', '\\', '"', '#');
else
$metaChars = array('*', '(', ')', '\\', chr(0));
$quotedMetaChars = array();
foreach ($metaChars as $key => $value) $quotedMetaChars[$key] =
'\\'.str_pad(dechex(ord($value)), 2, '0');
$str=str_replace($metaChars,$quotedMetaChars,$str); //replace them
return ($str);
}
?>
--was--
A better ldap_escape, if you don't need nested filters such as those in the Pear package.
Escapes for both filters and distinguished names.
function ldap_escape($str, $for_dn = false)
{
// see:
// RFC2254
// http://msdn.microsoft.com/en-us/library/ms675768(VS.85).aspx
// http://www-03.ibm.com/systems/i/software/ldap/underdn.html
if ($for_dn)
$metaChars = array(',','=', '+',
'<','>',';', '\\', '"', '#');
else
$metaChars = array('*', '(', ')', '\\', chr(0));
$quotedMetaChars = array();
foreach ($metaChars as $key => $value) $quotedMetaChars[$key] =
'\\'.str_pad(dechex(ord($value)), 2, '0');
$str=str_replace($metaChars,$quotedMetaChars,$str); //replace them
return ($str);
}
http://php.net/manual/en/function.ldap-search.php