note 35808 added to function.ldap-explode-dn

From: Date: Mon, 15 Sep 2003 13:06:18 +0000
Subject: note 35808 added to function.ldap-explode-dn
Groups: php.notes 
Request: Send a blank email to php-notes+get-56526@lists.php.net to get a copy of this message
If your DN contains < or > characters, you must escape them with a backslash or ldap_explode_dn() will give you a "wrong parameter count" error or even a segmentation fault. For example, these calls will fail with a "wrong parameter count" or a seg fault: ldap_explode_dn( "cn=<bob>,dc=example,dc=com", 0 ); ldap_explode_dn( 'cn=<bob>,dc=example,dc=com', 0 ); But this will succeed ldap_explode_dn( "cn=\<bob\>,dc=example,dc=com", 0 ); Notice also that the < and > are escaped with hex codes as noted above. This function is a nice wrapper that properly formats all DNs and can safely be called with < and > characters, and UTF-8 characters: function my_explode_dn( $dn, $with_attributes=0 ) { $dn = addcslashes( $dn, "<>" ); $result = ldap_explode_dn( $dn, $with_attributes ); //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; } I am using php 4.3.1. Good luck! ---- 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+35808 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35808&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35808&report=yes

« previous php.notes (#56526) next »