reference/strings/functions/addcslashes.xml
45042fef652f1b4e904e809fcbfcf31f6c60670b
45042fef652f1b4e904e809fcbfcf31f6c60670b
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.addcslashes">
3
+
<refentry xml:id="function.addcslashes" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>addcslashes</refname>
6
6
<refpurpose>Quote string with slashes in a C style</refpurpose>
...
...
@@ -10,12 +10,12 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>addcslashes</methodname>
13
-
<methodparam><type>string</type><parameter>str</parameter></methodparam>
14
-
<methodparam><type>string</type><parameter>charlist</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>string</parameter></methodparam>
14
+
<methodparam><type>string</type><parameter>characters</parameter></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
Returns a string with backslashes before characters that are
18
-
listed in <parameter>charlist</parameter> parameter.
18
+
listed in <parameter>characters</parameter> parameter.
19
19
</para>
20
20
</refsect1>
21
21
...
...
@@ -24,7 +24,7 @@
24
24
<para>
25
25
<variablelist>
26
26
<varlistentry>
27
-
<term><parameter>str</parameter></term>
27
+
<term><parameter>string</parameter></term>
28
28
<listitem>
29
29
<para>
30
30
The string to be escaped.
...
...
@@ -32,21 +32,22 @@
32
32
</listitem>
33
33
</varlistentry>
34
34
<varlistentry>
35
-
<term><parameter>charlist</parameter></term>
35
+
<term><parameter>characters</parameter></term>
36
36
<listitem>
37
37
<para>
38
38
A list of characters to be escaped. If
39
-
<parameter>charlist</parameter> contains characters
39
+
<parameter>characters</parameter> contains characters
40
40
<literal>\n</literal>, <literal>\r</literal> etc., they are
41
41
converted in C-like style, while other non-alphanumeric characters
42
42
with ASCII codes lower than 32 and higher than 126 converted to
43
43
octal representation.
44
44
</para>
45
45
<para>
46
-
When you define a sequence of characters in the charlist argument
46
+
When you define a sequence of characters in the <parameter>characters</parameter> argument
47
47
make sure that you know what characters come between the
48
48
characters that you set as the start and end of the range.
49
-
<informalexample>
49
+
<example>
50
+
<title><function>addcslashes</function> with Ranges</title>
50
51
<programlisting role="php">
51
52
<![CDATA[
52
53
<?php
...
...
@@ -57,13 +58,14 @@ echo addcslashes('foo[ ]', 'A..z');
57
58
?>
58
59
]]>
59
60
</programlisting>
60
-
</informalexample>
61
+
</example>
61
62
Also, if the first character in a range has a higher ASCII value
62
63
than the second character in the range, no range will be
63
64
constructed. Only the start, end and period characters will be
64
65
escaped. Use the <function>ord</function> function to find the
65
66
ASCII value for a character.
66
-
<informalexample>
67
+
<example>
68
+
<title><function>addcslashes</function> with Characters in Wrong Order</title>
67
69
<programlisting role="php">
68
70
<![CDATA[
69
71
<?php
...
...
@@ -72,15 +74,16 @@ echo addcslashes("zoo['.']", 'z..A');
72
74
?>
73
75
]]>
74
76
</programlisting>
75
-
</informalexample>
77
+
</example>
76
78
</para>
77
79
<para>
78
-
Be careful if you choose to escape characters 0, a, b, f, n, r,
79
-
t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t
80
-
and \v.
81
-
In PHP \0 (NULL), \r (carriage return), \n (newline), \f (form feed),
82
-
\v (vertical tab) and \t (tab) are predefined escape sequences,
83
-
while in C all of these are predefined escape sequences.
80
+
Be careful if you choose to escape characters 0, a, b, f, n, r, t and
81
+
v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v, all of
82
+
which are predefined escape sequences in C. Many of these sequences are
83
+
also defined in other C-derived languages, including PHP, meaning that
84
+
you may not get the desired result if you use the output of
85
+
<function>addcslashes</function> to generate code in those languages
86
+
with these characters defined in <parameter>characters</parameter>.
84
87
</para>
85
88
</listitem>
86
89
</varlistentry>
...
...
@@ -95,41 +98,19 @@ echo addcslashes("zoo['.']", 'z..A');
95
98
</para>
96
99
</refsect1>
97
100
98
-
<refsect1 role="changelog">
99
-
&reftitle.changelog;
100
-
<para>
101
-
<informaltable>
102
-
<tgroup cols="2">
103
-
<thead>
104
-
<row>
105
-
<entry>&Version;</entry>
106
-
<entry>&Description;</entry>
107
-
</row>
108
-
</thead>
109
-
<tbody>
110
-
<row>
111
-
<entry>5.2.5</entry>
112
-
<entry>
113
-
The escape sequences \v and \f were added.
114
-
</entry>
115
-
</row>
116
-
</tbody>
117
-
</tgroup>
118
-
</informaltable>
119
-
</para>
120
-
</refsect1>
121
-
122
101
<refsect1 role="examples">
123
102
&reftitle.examples;
124
103
<para>
125
-
<parameter>charlist</parameter> like "\0..\37", which would
104
+
<parameter>characters</parameter> like "\0..\37", which would
126
105
escape all characters with ASCII code between 0 and 31.
127
106
<example>
128
107
<title><function>addcslashes</function> example</title>
129
108
<programlisting role="php">
130
109
<![CDATA[
131
110
<?php
111
+
$not_escaped = "PHP isThirty\nYears Old!\tYay to the Elephant!\n";
132
112
$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
113
+
echo $escaped;
133
114
?>
134
115
]]>
135
116
</programlisting>
...
...
@@ -151,7 +132,6 @@ $escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
151
132
</refsect1>
152
133
153
134
</refentry>
154
-
155
135
<!-- Keep this comment at the end of the file
156
136
Local variables:
157
137
mode: sgml
158
138