douxieti6851 2014-03-18 16:06
浏览 32
已采纳

在PHP中读取数组值并分配给单个字符串

I have a PHP array which gives this result:

Array
(
  [count] => 1
  [0] => Array
  (
    [sn] => Array
    (
      [count] => 1
      [0] => Smith
    )
    [0] => sn
    [givenname] => Array
    (
      [count] => 1
      [0] => John
    )
    [1] => givenname
    [mail] => Array
    (
      [count] => 1
      [0] => john.smith@mydomain.com
    )
    [2] => mail
    [count] => 3
    [dn] => CN=John Smith,OU=IT Admin,DC=mylocaldomain,DC=local
  )
)

How do I go about extracting the Email address from this array result into a single string? I need to able to reference the Email address, but can't find a way to pull that information out.

The meat of the LDAP code is along the lines of:

$dn = “OU=IT Admin,DC=mylocaldomain,DC=local”;
$ds = $ldapconnectionstring;
$person = “johnsmith”;
$filter="(|(sn=$person*)(samaccountname=$person*))";
$justthese = array("ou", "sn", "givenname", "mail");
$sr=ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);

echo '<pre>'; print_r($info); echo '<pre/>';

I've googled this to death, read the PHP documentation about arrays, and read various similar posts here, but nothing seems to work for me.

I need to end up with:

 echo $email;

and get back:

 john.smith@mydomain.com
  • 写回答

2条回答 默认 最新

  • douling1936 2014-03-18 16:10
    关注

    All you need to do is read what print_r() shows you.

    (Array) [0](Array) > [mail](Array) > [0](string) => john.smith@mydomain.com
    
    $info = ldap_get_entries($ds, $sr);
    $email = $info[0]['mail'][0];
    echo $email;
    

    See the section Accessing array elements with square bracket syntax on these docs http://docs.php.net/manual/en/language.types.array.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序