我需要从ldap查询转换字符串。我正在查询Active Directory服务器上的用户帐户。这是我拉的绳子。
"CN=Phil Robertson,OU=Users,OU=Duck Commander,OU=Department & Buildings,DC=OCSDtest,DC=local"
我想把它转换成一个像这样的数组
$array['local']['OCtest']['Department & Buildings']['Duck Commander']['Users']['Phil Robertson']=1;
不$array( [1]=>'local,[2]=>'OCtest',[3]='Depart',[4]='Duck Commander',[5]='Users');
目前我有
示例代码——
$dnn2 = ldap_explode_dn("CN=Phil Robertson,OU=Users,OU=Duck Commander,OU=Department & Buildings,DC=OCSDtest,DC=local",1);
unset($dnn2['count']);
echo "<pre>";
print_r(array_reverse($dnn2));
我需要什么?
试试这个
$arrayvalue = array();
foreach($dnn2 as $dn)
{
$temp = explode('=',$dn);
$temp1 = substr($temp[1], 0, strpos($temp1[1], ','));
$arrayvalue[] = $temp1;
}
print_r($arrayvalue);
$dnn2 = ldap_explode_dn("CN=Phil Robertson,OU=Users,OU=Duck Commander,OU=Department & Buildings,DC=OCSDtest,DC=local",1);
unset($dnn2['count']);
$result = null;
$ref =& $result;
foreach (array_reverse($dnn2) as $dn) {
$ref = array($dn => null);
$ref =& $ref[$dn];
}
print_r($result);
试试这个
$a = array();
foreach($dnn2 as $dn)
{
$arr = explode('=',$dn);
$a[] = $arr[1]; //or $a[] = array($arr[1]); for 6 dimensional array
}
print_r($a);