1

我需要从 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));

我需要什么?

4

3 回答 3

1

试试这个

 $arrayvalue = array();
    foreach($dnn2 as $dn)
    {
       $temp  = explode('=',$dn);
       $temp1 =  substr($temp[1], 0, strpos($temp1[1], ',')); 
       $arrayvalue[]  = $temp1;
    }

    print_r($arrayvalue);
于 2013-01-19T05:37:12.337 回答
0

试试这个

$a = array();
foreach($dnn2 as $dn)
{
   $arr = explode('=',$dn);
   $a[] = $arr[1];  //or $a[] = array($arr[1]); for 6 dimensional array
}

print_r($a);
于 2013-01-19T05:26:11.343 回答
0
$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);
于 2013-01-19T06:09:31.627 回答