清理解析ldap查询结果的方法

I am parsing the results of an ldap call to an active directory. I am trying to get all users in a security group. Here are my results:

    $res =    [member] => Array
            (
                [count] => 2
                [0] => CN=User 1,OU=SomeOU,DC=someDC,DC= someDC2
                [1] => CN=User 2,OU=SomeOU,DC= someDC,DC= someDC2
            )

Is there a cleaner way to get the name of out the results? (i.e. User 1,User 2)

         foreach ($res['member'] as $k => $v){
             $exp = explode("=",$v);
             $exp = explode(",",$exp[1]);
             $name = $exp[0];
             echo $name."
";
         }

Not sure that it's more clear way to do this, but you can use preg_match function.

foreach($member as $key => $value) {
    $matches = [];
    if (preg_match('/^CN=(.*?),OU/', $member, $matches)) {
        echo "$matches[1]
";
    }
}