doushai7225 2010-07-20 05:39
浏览 57
已采纳

问题替换LDAP默认属性

$entries = ldap_get_entries($ldapconn, $ldapsearch); // This is my result form ldap server
$format = "@sn, @givenname, E: @mail"; // This are new strings to replace ldap defualt attribures.

if ( $entries ) { // Check $entries are not empty.

    # Try to authenticate to each until we get a match
    for ( $i = 0 ;  $i < $entries['count']; $i++ ) {

        $result = $format;
        foreach ($entries[$i] as $key => $entrie) {
            echo $result."
";
            $result = str_replace($result, '@'.$key, $entrie[0]);// This is the problem I'm having I try to replace the strings from $result but doesn't looks like it's working.
            //$cat = $entries[$i][$key][0];

            $contact_data[] = $result;

        }
        var_dump($result);
        die();
    }
}

print json_encode($contact_data);
  • 写回答

1条回答 默认 最新

  • douchangmian0305 2010-07-20 08:37
    关注

    Look at the documentation of str_replace:

    http://www.php3.de/str_replace

    str_replace ( $search , $replace , $subject )

    Example:

    $search = "@sn";
    $replace = "Foobar";
    $subject = "ABC @sn DEF";
    echo str_replace  (   $search  ,   $replace  ,   $subject )
    

    This would print "ABC Foobar DEF"

    So it looks like you have to fix the order of the parameters to the str_replace function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的