2010-07-20 79 views
0
$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."\n"; 
      $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

您正在搜索整個字符串:'@sn,@givenname,E:@ mail'我相信您想搜索其中的一個?我是對的嗎? – 2010-07-20 05:47:59

回答

0

看str_replace函數的文檔:

http://www.php3.de/str_replace

str_replace函數($搜索,$替換,​​$主題)

實施例:

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

這將打印「ABC Foobar DEF」

所以它看起來像你必須修復str_replace函數參數的順序。

+0

現在感謝它的作品。 – Dawit 2010-07-20 13:01:32