reference/strings/functions/strrpos.xml
2eb2cdbe58d2f35cb88ad06fa090f3c0ccd9f860
...
...
@@ -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.strrpos">
3
+
<refentry xml:id="function.strrpos" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>strrpos</refname>
6
6
<refpurpose>Find the position of the last occurrence of a substring in a string</refpurpose>
...
...
@@ -9,9 +9,9 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>int</type><methodname>strrpos</methodname>
12
+
<type class="union"><type>int</type><type>false</type></type><methodname>strrpos</methodname>
13
13
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
14
-
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
14
+
<methodparam><type>string</type><parameter>needle</parameter></methodparam>
15
15
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>
...
...
@@ -35,6 +35,9 @@
35
35
<varlistentry>
36
36
<term><parameter>needle</parameter></term>
37
37
<listitem>
38
+
<para>
39
+
The string to search for.
40
+
</para>
38
41
&strings.parameter.needle.non-string;
39
42
</listitem>
40
43
</varlistentry>
...
...
@@ -42,9 +45,22 @@
42
45
<term><parameter>offset</parameter></term>
43
46
<listitem>
44
47
<para>
45
-
If specified, search will start this number of characters counted from the
46
-
beginning of the string. If the value is negative, search will instead start
47
-
from that many characters from the end of the string, searching backwards.
48
+
If zero or positive, the search is performed left to right skipping the
49
+
first <parameter>offset</parameter> bytes of the
50
+
<parameter>haystack</parameter>.
51
+
</para>
52
+
<para>
53
+
If negative, the search starts <parameter>offset</parameter> bytes from
54
+
the right instead of from the beginning of <parameter>haystack</parameter>.
55
+
The search is performed right to left, searching for the first
56
+
occurrence of <parameter>needle</parameter> from the selected byte.
57
+
<note>
58
+
<para>
59
+
This is effectively looking for the last occurrence of
60
+
<parameter>needle</parameter> at or before the last
61
+
<parameter>offset</parameter> bytes.
62
+
</para>
63
+
</note>
48
64
</para>
49
65
</listitem>
50
66
</varlistentry>
...
...
@@ -58,7 +74,11 @@
58
74
Returns the position where the needle exists relative to the beginning of
59
75
the <parameter>haystack</parameter> string (independent of search direction
60
76
or offset).
61
-
Also note that string positions start at 0, and not 1.
77
+
<note>
78
+
<simpara>
79
+
String positions start at 0, and not 1.
80
+
</simpara>
81
+
</note>
62
82
</para>
63
83
<para>
64
84
Returns &false; if the needle was not found.
...
...
@@ -68,27 +88,31 @@
68
88

69
89
<refsect1 role="changelog">
70
90
&reftitle.changelog;
71
-
<para>
72
-
<informaltable>
73
-
<tgroup cols="2">
74
-
<thead>
75
-
<row>
76
-
<entry>&Version;</entry>
77
-
<entry>&Description;</entry>
78
-
</row>
79
-
</thead>
80
-
<tbody>
81
-
<row>
82
-
<entry>5.0.0</entry>
83
-
<entry>
84
-
The <parameter>needle</parameter> may now be a string of more than one
85
-
character.
86
-
</entry>
87
-
</row>
88
-
</tbody>
89
-
</tgroup>
90
-
</informaltable>
91
-
</para>
91
+
<informaltable>
92
+
<tgroup cols="2">
93
+
<thead>
94
+
<row>
95
+
<entry>&Version;</entry>
96
+
<entry>&Description;</entry>
97
+
</row>
98
+
</thead>
99
+
<tbody>
100
+
&strings.changelog.needle-empty;
101
+
<row>
102
+
<entry>8.0.0</entry>
103
+
<entry>
104
+
Passing an &integer; as <parameter>needle</parameter> is no longer supported.
105
+
</entry>
106
+
</row>
107
+
<row>
108
+
<entry>7.3.0</entry>
109
+
<entry>
110
+
Passing an &integer; as <parameter>needle</parameter> has been deprecated.
111
+
</entry>
112
+
</row>
113
+
</tbody>
114
+
</tgroup>
115
+
</informaltable>
92
116
</refsect1>
93
117

94
118
<refsect1 role="examples">
...
...
@@ -123,16 +147,41 @@ if ($pos === false) { // note: three equal signs
123
147
<?php
124
148
$foo = "0123456789a123456789b123456789c";
125
149

126
-
var_dump(strrpos($foo, '7', -5)); // Starts looking backwards five positions
127
-
// from the end. Result: int(17)
150
+
// Looking for '0' from the 0th byte (from the beginning)
151
+
var_dump(strrpos($foo, '0', 0));
152
+

153
+
// Looking for '0' from the 1st byte (after byte "0")
154
+
var_dump(strrpos($foo, '0', 1));
128
155

129
-
var_dump(strrpos($foo, '7', 20)); // Starts searching 20 positions into the
130
-
// string. Result: int(27)
156
+
// Looking for '7' from the 21th byte (after byte 20)
157
+
var_dump(strrpos($foo, '7', 20));
131
158

132
-
var_dump(strrpos($foo, '7', 28)); // Result: bool(false)
159
+
// Looking for '7' from the 29th byte (after byte 28)
160
+
var_dump(strrpos($foo, '7', 28));
161
+

162
+
// Looking for '7' right to left from the 5th byte from the end
163
+
var_dump(strrpos($foo, '7', -5));
164
+

165
+
// Looking for 'c' right to left from the 2nd byte from the end
166
+
var_dump(strrpos($foo, 'c', -2));
167
+

168
+
// Looking for '9c' right to left from the 2nd byte from the end
169
+
var_dump(strrpos($foo, '9c', -2));
133
170
?>
134
171
]]>
135
172
</programlisting>
173
+
&example.outputs;
174
+
<screen>
175
+
<![CDATA[
176
+
int(0)
177
+
bool(false)
178
+
int(27)
179
+
bool(false)
180
+
int(17)
181
+
bool(false)
182
+
int(29)
183
+
]]>
184
+
</screen>
136
185
</example>
137
186
</para>
138
187
</refsect1>
...
...
@@ -151,7 +200,6 @@ var_dump(strrpos($foo, '7', 28)); // Result: bool(false)
151
200
</refsect1>
152
201

153
202
</refentry>
154
-

155
203
<!-- Keep this comment at the end of the file
156
204
Local variables:
157
205
mode: sgml
158
206