reference/ldap/functions/ldap-escape.xml
bc90525a5a5ebcf8412ef34b8355d2de12166fff
...
...
@@ -11,8 +11,8 @@
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>ldap_escape</methodname>
13
13
<methodparam><type>string</type><parameter>value</parameter></methodparam>
14
-
<methodparam choice="opt"><type>string</type><parameter>ignore</parameter></methodparam>
15
-
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
14
+
<methodparam choice="opt"><type>string</type><parameter>ignore</parameter><initializer>""</initializer></methodparam>
15
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Escapes <parameter>value</parameter> for use in the context implied by
...
...
@@ -48,6 +48,7 @@
48
48
<constant>LDAP_ESCAPE_FILTER</constant> for filters to be used with
49
49
<function>ldap_search</function>, or
50
50
<constant>LDAP_ESCAPE_DN</constant> for DNs.
51
+
If neither flag is passed, all chars are escaped.
51
52
</para>
52
53
</listitem>
53
54
</varlistentry>
...
...
@@ -61,6 +62,34 @@
61
62
Returns the escaped string.
62
63
</para>
63
64
</refsect1>
65
+

66
+
<refsect1 role="examples">
67
+
&reftitle.examples;
68
+
<para>
69
+
When building an LDAP filter, you should use ldap_escape with LDAP_ESCAPE_FILTER flag.
70
+
<example>
71
+
<title>Searching for an email address</title>
72
+
<programlisting role="php">
73
+
<![CDATA[
74
+
<?php
75
+
// $ds is a valid LDAP\Connection instance for a directory server
76
+

77
+
// $mail is an email address provided by the user in a form
78
+

79
+
$base = "o=My Company, c=US";
80
+
$filter = "(mail=".ldap_escape($mail, "", LDAP_ESCAPE_FILTER).")";
81
+

82
+
$sr = ldap_search($ds, $base, $filter, array("sn", "givenname", "mail"));
83
+

84
+
$info = ldap_get_entries($ds, $sr);
85
+

86
+
echo $info["count"]." entries returned\n";
87
+
?>
88
+
]]>
89
+
</programlisting>
90
+
</example>
91
+
</para>
92
+
</refsect1>
64
93
</refentry>
65
94

66
95
<!-- Keep this comment at the end of the file
67
96