note 34724 added to function.ldap-explode-dn

From: Date: Tue, 05 Aug 2003 07:27:26 +0000
Subject: note 34724 added to function.ldap-explode-dn
Groups: php.notes 
Request: Send a blank email to php-notes+get-53386@lists.php.net to get a copy of this message
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" } ---- Manual Page -- http://www.php.net/manual/en/function.ldap-explode-dn.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34724 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34724&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34724&report=yes

« previous php.notes (#53386) next »