I'm trying to update my Active Directory using php and the ldap_modify_batch() function. When I'm calling the function everything works fine, but sometimes, a user enters an accented character. Therefore the edited field in my AD is not containing the accented character (like "é"), but it contain his equivalence in an other encoding standard(like "ã©").
Here is an exemple :
User input -ldap_modify_batch()-> Result in my AD
"Comptabilité" -ldap_modify_batch()-> "Comptabilité"
Here is the code for the specified arguments
$modifs = [
[
"attrib" => "telephoneNumber",
"modtype" => LDAP_MODIFY_BATCH_REPLACE,
"values" => ["0123456789"],
],
[
"attrib" => "mail",
"modtype" => LDAP_MODIFY_BATCH_REPLACE,
"values" => ["amail@amail.com"],
],
[
"attrib" => "description",
"modtype" => LDAP_MODIFY_BATCH_REPLACE,
"values" => ["Comptabilité"],
],
[
"attrib" => "physicalDeliveryOfficeName",
"modtype" => LDAP_MODIFY_BATCH_REPLACE,
"values" => ["AOfficName"],
],
];
ldap_modify_batch($connect, $dn, $modifs);
What should i do to bring the accents in my AD ?
Is there something i should change in my php.ini or elsewhere ?
So, here is the solution we've founded :
You must encode your string in "ISO-8859-1" instead of "UTF-8" (I haven't any informations about why).
To encode your string you must use the php function iconv()
Here is how i fixed my problem :
$office = "Comptabilité";
$value_ready_to_send = iconv(mb_detect_encoding($office),"ISO-8859-1",$office);