reference/strings/functions/strrchr.xml
654ee5c8afdf4ee721befdd0937fa155c50dca43
...
...
@@ -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.strrchr">
3
+
<refentry xml:id="function.strrchr" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>strrchr</refname>
6
6
<refpurpose>Find the last occurrence of a character in a string</refpurpose>
...
...
@@ -9,9 +9,10 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>string</type><methodname>strrchr</methodname>
12
+
<type class="union"><type>string</type><type>false</type></type><methodname>strrchr</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
+
<methodparam choice="opt"><type>bool</type><parameter>before_needle</parameter><initializer>&false;</initializer></methodparam>
15
16
</methodsynopsis>
16
17
<para>
17
18
This function returns the portion of <parameter>haystack</parameter> which
...
...
@@ -43,6 +44,16 @@
43
44
&strings.parameter.needle.non-string;
44
45
</listitem>
45
46
</varlistentry>
47
+
<varlistentry>
48
+
<term><parameter>before_needle</parameter></term>
49
+
<listitem>
50
+
<para>
51
+
If &true;, <function>strrchr</function>
52
+
returns the part of the <parameter>haystack</parameter> before the
53
+
last occurrence of the <parameter>needle</parameter> (excluding the needle).
54
+
</para>
55
+
</listitem>
56
+
</varlistentry>
46
57
</variablelist>
47
58
</para>
48
59
</refsect1>
...
...
@@ -57,26 +68,37 @@
57
68

58
69
<refsect1 role="changelog">
59
70
&reftitle.changelog;
60
-
<para>
61
-
<informaltable>
62
-
<tgroup cols="2">
63
-
<thead>
64
-
<row>
65
-
<entry>&Version;</entry>
66
-
<entry>&Description;</entry>
67
-
</row>
68
-
</thead>
69
-
<tbody>
70
-
<row>
71
-
<entry>4.3.0</entry>
72
-
<entry>
73
-
This function is now binary safe.
74
-
</entry>
75
-
</row>
76
-
</tbody>
77
-
</tgroup>
78
-
</informaltable>
79
-
</para>
71
+
<informaltable>
72
+
<tgroup cols="2">
73
+
<thead>
74
+
<row>
75
+
<entry>&Version;</entry>
76
+
<entry>&Description;</entry>
77
+
</row>
78
+
</thead>
79
+
<tbody>
80
+
<row>
81
+
<entry>8.3.0</entry>
82
+
<entry>
83
+
The <parameter>before_needle</parameter> parameter was added.
84
+
</entry>
85
+
</row>
86
+
&strings.changelog.needle-empty;
87
+
<row>
88
+
<entry>8.0.0</entry>
89
+
<entry>
90
+
Passing an &integer; as <parameter>needle</parameter> is no longer supported.
91
+
</entry>
92
+
</row>
93
+
<row>
94
+
<entry>7.3.0</entry>
95
+
<entry>
96
+
Passing an &integer; as <parameter>needle</parameter> has been deprecated.
97
+
</entry>
98
+
</row>
99
+
</tbody>
100
+
</tgroup>
101
+
</informaltable>
80
102
</refsect1>
81
103

82
104
<refsect1 role="examples">
...
...
@@ -87,15 +109,20 @@
87
109
<programlisting role="php">
88
110
<![CDATA[
89
111
<?php
90
-
// get last directory in $PATH
91
-
$dir = substr(strrchr($PATH, ":"), 1);
92
-

93
-
// get everything after last newline
94
-
$text = "Line 1\nLine 2\nLine 3";
95
-
$last = substr(strrchr($text, 10), 1 );
112
+
$ext = strrchr('somefile.txt', '.');
113
+
echo "file extension: $ext \n";
114
+
$ext = $ext ? strtolower(substr($ext, 1)) : '';
115
+
echo "file extension: $ext";
96
116
?>
97
117
]]>
98
118
</programlisting>
119
+
&example.outputs.similar;
120
+
<screen>
121
+
<![CDATA[
122
+
file extension: .txt
123
+
file extension: txt
124
+
]]>
125
+
</screen>
99
126
</example>
100
127
</para>
101
128
</refsect1>
...
...
@@ -116,7 +143,6 @@ $last = substr(strrchr($text, 10), 1 );
116
143
</refsect1>
117
144

118
145
</refentry>
119
-

120
146
<!-- Keep this comment at the end of the file
121
147
Local variables:
122
148
mode: sgml
123
149