How can the search string be modified to accommodate usernames with a dot (.) in PHP LDAP queries?

When searching for usernames with a dot (.) in PHP LDAP queries, the dot must be escaped with a backslash (\) to ensure it is treated as a literal character and not as a wildcard. This can be done by modifying the search string to include the escaped dot (\.) before querying the LDAP server.

// Modify the search string to accommodate usernames with a dot (.) in PHP LDAP queries
$username = 'user.name'; // Username with a dot
$escapedUsername = ldap_escape($username, null, LDAP_ESCAPE_FILTER);
$searchString = "(sAMAccountName=$escapedUsername)";

// Perform LDAP search with the modified search string
$ldapSearch = ldap_search($ldapConnection, $ldapBaseDN, $searchString);