note 109482 added to function.ldap-explode-dn

From: Date: Fri, 20 Jul 2012 19:20:19 +0000
Subject: note 109482 added to function.ldap-explode-dn
Groups: php.notes 
Request: Send a blank email to php-notes+get-189341@lists.php.net to get a copy of this message
I came accros this page and enjoyed the comments. Since a LDAP string can sometimes be lengthy and have many attributes, I needed to be able to sort through all that is in. In my case, I needed to get the subdomain part and other parameters. Here is how I built my method. /** * Parse, and format a DN string to Array * * Read a LDAP DN, and return an array keys * listing all similar attributes. * * Also takes care of the character escape and unescape * * Example: * CN=username,OU=UNITNAME,OU=Region,OU=Country,DC=subdomain,DC=domain,DC=com * * Would normally return: * Array ( * [count] => 9 * [0] => CN=username * [1] => OU=UNITNAME * [2] => OU=Region * [5] => OU=Country * [6] => DC=subdomain * [7] => DC=domain * [8] => DC=com * ) * * Returns instead a manageable array: * array ( * [CN] => array( username ) * [OU] => array( UNITNAME, Region, Country ) * [DC] => array ( subdomain, domain, com ) * ) * * * @author gabriel at hrz dot uni-marburg dot de 05-Aug-2003 02:27 (part of the character replacement) * @author Renoir Boulanger * * @param string $dn The DN * @return array */ function parseLdapDn($dn) { $parsr=ldap_explode_dn($dn, 0); //$parsr[] = 'EE=Sôme Krazï string'; //$parsr[] = 'AndBogusOne'; $out = array(); foreach($parsr as $key=>$value){ if(FALSE !== strstr($value, '=')){ list($prefix,$data) = explode("=",$value); $data=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $data); if(isset($current_prefix) && $prefix == $current_prefix){ $out[$prefix][] = $data; } else { $current_prefix = $prefix; $out[$prefix][] = $data; } } } return $out; } ---- Server IP: 69.147.83.197 Probable Submitter: 192.75.88.232 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-explode-dn.php Edit -- https://master.php.net/note/edit/109482 Del: integrated -- https://master.php.net/note/delete/109482/integrated Del: useless -- https://master.php.net/note/delete/109482/useless Del: bad code -- https://master.php.net/note/delete/109482/bad+code Del: spam -- https://master.php.net/note/delete/109482/spam Del: non-english -- https://master.php.net/note/delete/109482/non-english Del: in docs -- https://master.php.net/note/delete/109482/in+docs Del: other reasons-- https://master.php.net/note/delete/109482 Reject -- https://master.php.net/note/reject/109482 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189341) next »