Keep attention on UTF8 encoded DNs. Since openLDAP >=2.1.2
ldap_explode_dn turns unprintable chars (in the ASCII sense, UTF8
encoded) into \<hexcode>.
Example:
$dn="ou=Universität ,c=DE";
var_dump(ldap_explode_dn($dn,0));
//returns
array(3) {
["count"]=>
int(2)
[0]=>
string(19) "ou=Universit\C3\A4t"
[1]=>
string(4) "c=DE"
}
Unfortunately, PHP don't support the ldap functions ldap_str2dn and
ldap_dn2str, but by means of preg_replace a workaround is possible to
recover the old behaviour of ldap_explode_dn
// workaround
function myldap_explode_dn($dn,$with_attribute){
$result=ldap_explode_dn ($dn, $with_attrib);
//translate hex code into ascii again
foreach($result as $key=>$value){
$result[$key]=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value);
}
return($result);
}
//
//then follows for the example
$dn="ou=Universität ,c=DE";
var_dump(myldap_explode_dn($dn,0));
//returns
array(3) {
["count"]=>
int(2)
[0]=>
string(15) "ou=Universität"
[1]=>
string(4) "c=DE"
}