ldap_add: Invalid syntax
I'm trying to add an Active Directory record via PHP. The CN contains a apostrophe (single quote), and I'm trying to find the correct way to escape it.
Things I've tried:
$dn = "CN=Conan O'Brien,OU=test,DC=test";
ldap_add($link_id, $dn, $attributes);
ldap_add($link_id, addslashes($dn), $attributes);
ldap_add($l开发者_如何学运维ink_id, str_replace("'", "\\39", $dn), $attributes);
Each one gives the same error. Obviously, I have verified this code works without an apostrophe in the DN.
ldap_add(): Add: Invalid syntax
You need to use two apostrophes instead of one. It's because one escapes the other.
The \ escaping is used for special characters ("," ";" "=" etc...) and hexadecimal-encoded characters, which is used when the value has no string representation.
精彩评论