note 89508 added to function.ldap-get-entries
| From: | chl at osu1 dot php dot net | Date: | Wed, 11 Mar 2009 16:20:29 +0000 |
| Subject: | note 89508 added to function.ldap-get-entries | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151741@lists.php.net to get a copy of this message | ||
Recursive form of markus' function so it can take directly the result of ldap_get_entries :
<?php
function cleanUpEntry( $entry ) {
$retEntry = array();
for ( $i = 0; $i < $entry['count']; $i++ ) {
if (is_array($entry[$i])) {
$subtree = $entry[$i];
//This condition should be superfluous so just take the recursive call
//adapted to your situation in order to increase perf.
if ( ! empty($subtree['dn']) and ! isset($retEntry[$subtree['dn']])) {
$retEntry[$subtree['dn']] = cleanUpEntry($subtree);
}
else {
$retEntry[] = cleanUpEntry($subtree);
}
}
else {
$attribute = $entry[$i];
if ( $entry[$attribute]['count'] == 1 ) {
$retEntry[$attribute] = $entry[$attribute][0];
} else {
for ( $j = 0; $j < $entry[$attribute]['count']; $j++ ) {
$retEntry[$attribute][] = $entry[$attribute][$j];
}
}
}
}
return $retEntry;
}
?>
Result is of the form :
array(256) {
["uid=doe,ou=People,dc=example,dc=net"]=>
array(3) {
["uid"]=>
string(4) "doe"
["cn"]=>
string(14) "John Doe"
["telephonenumber"]=>
string(4) "1234"
}
["uid=foo,ou=People,dc=example,dc=net"]=>
...
----
Server IP: 89.31.146.176
Probable Submitter: 157.136.38.178
----
Manual Page -- http://www.php.net/manual/en/function.ldap-get-entries.php
Edit -- https://master.php.net/note/edit/89508
Del: integrated -- https://master.php.net/note/delete/89508/integrated
Del: useless -- https://master.php.net/note/delete/89508/useless
Del: bad code -- https://master.php.net/note/delete/89508/bad+code
Del: spam -- https://master.php.net/note/delete/89508/spam
Del: non-english -- https://master.php.net/note/delete/89508/non-english
Del: in docs -- https://master.php.net/note/delete/89508/in+docs
Del: other reasons-- https://master.php.net/note/delete/89508
Reject -- https://master.php.net/note/reject/89508
Search -- https://master.php.net/manage/user-notes.php