reference/strings/functions/strcspn.xml
422bb032237525aaf50e6a43f33362a2c610a1d7
...
...
@@ -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.strcspn">
3
+
<refentry xml:id="function.strcspn" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>strcspn</refname>
6
6
<refpurpose>Find length of initial segment not matching mask</refpurpose>
...
...
@@ -10,15 +10,23 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>int</type><methodname>strcspn</methodname>
13
-
<methodparam><type>string</type><parameter>str1</parameter></methodparam>
14
-
<methodparam><type>string</type><parameter>str2</parameter></methodparam>
15
-
<methodparam choice="opt"><type>int</type><parameter>start</parameter></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>string</parameter></methodparam>
14
+
<methodparam><type>string</type><parameter>characters</parameter></methodparam>
15
+
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
16
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
17
17
</methodsynopsis>
18
18
<para>
19
19
Returns the length of the initial segment of
20
-
<parameter>str1</parameter> which does <emphasis>not</emphasis>
21
-
contain any of the characters in <parameter>str2</parameter>.
20
+
<parameter>string</parameter> which does <emphasis>not</emphasis>
21
+
contain any of the characters in <parameter>characters</parameter>.
22
+
</para>
23
+
<para>
24
+
If <parameter>offset</parameter> and <parameter>length</parameter>
25
+
are omitted, then all of <parameter>string</parameter> will be
26
+
examined. If they are included, then the effect will be the same as
27
+
calling <literal>strcspn(substr($string, $offset, $length),
28
+
$characters)</literal> (see <xref linkend="function.substr"/>
29
+
for more information).
22
30
</para>
23
31
</refsect1>
24
32
...
...
@@ -27,26 +35,44 @@
27
35
<para>
28
36
<variablelist>
29
37
<varlistentry>
30
-
<term><parameter>str1</parameter></term>
38
+
<term><parameter>string</parameter></term>
31
39
<listitem>
32
40
<para>
33
-
The first string.
41
+
The string to examine.
34
42
</para>
35
43
</listitem>
36
44
</varlistentry>
37
45
<varlistentry>
38
-
<term><parameter>str2</parameter></term>
46
+
<term><parameter>characters</parameter></term>
39
47
<listitem>
40
48
<para>
41
-
The second string.
49
+
The string containing every disallowed character.
42
50
</para>
43
51
</listitem>
44
52
</varlistentry>
45
53
<varlistentry>
46
-
<term><parameter>start</parameter></term>
54
+
<term><parameter>offset</parameter></term>
47
55
<listitem>
48
56
<para>
49
-
The start position of the string to examine.
57
+
The position in <parameter>string</parameter> to
58
+
start searching.
59
+
</para>
60
+
<para>
61
+
If <parameter>offset</parameter> is given and is non-negative,
62
+
then <function>strcspn</function> will begin
63
+
examining <parameter>string</parameter> at
64
+
the <parameter>offset</parameter>'th position. For instance, in
65
+
the string '<literal>abcdef</literal>', the character at
66
+
position <literal>0</literal> is '<literal>a</literal>', the
67
+
character at position <literal>2</literal> is
68
+
'<literal>c</literal>', and so forth.
69
+
</para>
70
+
<para>
71
+
If <parameter>offset</parameter> is given and is negative,
72
+
then <function>strcspn</function> will begin
73
+
examining <parameter>string</parameter> at
74
+
the <parameter>offset</parameter>'th position from the end
75
+
of <parameter>string</parameter>.
50
76
</para>
51
77
</listitem>
52
78
</varlistentry>
...
...
@@ -54,7 +80,20 @@
54
80
<term><parameter>length</parameter></term>
55
81
<listitem>
56
82
<para>
57
-
The length of the string to examine.
83
+
The length of the segment from <parameter>string</parameter>
84
+
to examine.
85
+
</para>
86
+
<para>
87
+
If <parameter>length</parameter> is given and is non-negative,
88
+
then <parameter>string</parameter> will be examined
89
+
for <parameter>length</parameter> characters after the starting
90
+
position.
91
+
</para>
92
+
<para>
93
+
If <parameter>length</parameter> is given and is negative,
94
+
then <parameter>string</parameter> will be examined from the
95
+
starting position up to <parameter>length</parameter>
96
+
characters from the end of <parameter>string</parameter>.
58
97
</para>
59
98
</listitem>
60
99
</varlistentry>
...
...
@@ -65,33 +104,75 @@
65
104
<refsect1 role="returnvalues">
66
105
&reftitle.returnvalues;
67
106
<para>
68
-
Returns the length of the segment as an integer.
107
+
Returns the length of the initial segment of <parameter>string</parameter>
108
+
which consists entirely of characters <emphasis>not</emphasis> in <parameter>characters</parameter>.
69
109
</para>
110
+
<note>
111
+
<para>
112
+
When a <parameter>offset</parameter> parameter is set, the returned length
113
+
is counted starting from this position, not from the beginning of
114
+
<parameter>string</parameter>.
115
+
</para>
116
+
</note>
70
117
</refsect1>
71
118

72
119
<refsect1 role="changelog">
73
120
&reftitle.changelog;
74
-
<para>
75
-
<informaltable>
76
-
<tgroup cols="2">
77
-
<thead>
78
-
<row>
79
-
<entry>&Version;</entry>
80
-
<entry>&Description;</entry>
81
-
</row>
82
-
</thead>
83
-
<tbody>
84
-
<row>
85
-
<entry>4.3.0</entry>
86
-
<entry>
87
-
The <parameter>start</parameter> and <parameter>length</parameter>
88
-
were added
89
-
</entry>
90
-
</row>
91
-
</tbody>
92
-
</tgroup>
93
-
</informaltable>
94
-
</para>
121
+
<informaltable>
122
+
<tgroup cols="2">
123
+
<thead>
124
+
<row>
125
+
<entry>&Version;</entry>
126
+
<entry>&Description;</entry>
127
+
</row>
128
+
</thead>
129
+
<tbody>
130
+
<row>
131
+
<entry>8.0.0</entry>
132
+
<entry>
133
+
<parameter>length</parameter> is nullable now.
134
+
</entry>
135
+
</row>
136
+
</tbody>
137
+
</tgroup>
138
+
</informaltable>
139
+
</refsect1>
140
+

141
+
<refsect1 role="examples">
142
+
&reftitle.examples;
143
+
<example xml:id="strcspn.example">
144
+
<title><function>strcspn</function> example</title>
145
+
<programlisting role="php">
146
+
<![CDATA[
147
+
<?php
148
+
$a = strcspn('abcd', 'apple');
149
+
$b = strcspn('abcd', 'banana');
150
+
$c = strcspn('hello', 'l');
151
+
$d = strcspn('hello', 'world');
152
+
$e = strcspn('abcdhelloabcd', 'abcd', -9);
153
+
$f = strcspn('abcdhelloabcd', 'abcd', -9, -5);
154
+

155
+
var_dump($a);
156
+
var_dump($b);
157
+
var_dump($c);
158
+
var_dump($d);
159
+
var_dump($e);
160
+
var_dump($f);
161
+
?>
162
+
]]>
163
+
</programlisting>
164
+
&example.outputs;
165
+
<screen>
166
+
<![CDATA[
167
+
int(0)
168
+
int(0)
169
+
int(2)
170
+
int(2)
171
+
int(5)
172
+
int(4)
173
+
]]>
174
+
</screen>
175
+
</example>
95
176
</refsect1>
96
177
97
178
<refsect1 role="notes">
...
...
@@ -109,7 +190,6 @@
109
190
</refsect1>
110
191
111
192
</refentry>
112
-

113
193
<!-- Keep this comment at the end of the file
114
194
Local variables:
115
195
mode: sgml
116
196