tags:

views:

19

answers:

1
$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);
A: 

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.

Alex
Thank's it works now.
Dawit