问题
I am trying to get a list of users in a Active Directory group using php ldap_get_entries. I am able to connect to the ldap server and bind without a problem. This issue I have is the result I get from the array when using ldap_get_entires
. Here is what I am using to get the data from the group:
$result = ldap_search($ldapConn, $ldaptree, "(member=*"),array('member'));
$data = ldap_get_entries($ldapConn, $result);
print_r($data);
What I get is this:
Array([count] => 1 [0] => Array([member] => Array([count => 3 [0] => CN=Mike Jones,CN=Users,DC=DOMAIN,DC=NET [1] => CN=Van Smith,CN=Users,DC=DOMAIN,DC=NET [2] => CN=Jane Doe,CN=Users,DC=DOMAIN,DC=NET) [0] => member[count] => 1 [dn] => CN=Cool Guys,CN=Users,DC=DOMAIN,DC=NET))
How do I pull out just the names from this array to look like this?
Mike Jones
Van Smith
Jane Doe
回答1:
Thanks to @Thefourthbird for the suggestion. He suggested I use the following to take out the names I need.
foreach ($array[0]["member"] as $key => $member) {
if (is_int($key)) {
$User[] = explode('=', explode(',', $member)[0])[1] . PHP_EOL;
}
}
The only thing that was left to do was organize the data in alphabetical order. I used a array_multisort
function to do this.
array_multisort($User, SORT_ASC);
foreach ($User as $key => $SortUser) {
echo $SortUser;
}
Now all the names come out on their own line and in alphabetical order.
Jane Doe
Mike Jones
Van Smith
来源:https://stackoverflow.com/questions/61671384/how-to-pull-entries-out-of-ldap-get-entries-array