reference/strings/functions/substr-compare.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.substr-compare">
3
+
<refentry xml:id="function.substr-compare" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>substr_compare</refname>
6
6
<refpurpose>Binary safe comparison of two strings from an offset, up to length characters</refpurpose>
...
...
@@ -10,15 +10,15 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>int</type><methodname>substr_compare</methodname>
13
-
<methodparam><type>string</type><parameter>main_str</parameter></methodparam>
14
-
<methodparam><type>string</type><parameter>str</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
14
+
<methodparam><type>string</type><parameter>needle</parameter></methodparam>
15
15
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
17
-
<methodparam choice="opt"><type>bool</type><parameter>case_insensitivity</parameter><initializer>&false;</initializer></methodparam>
16
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
17
+
<methodparam choice="opt"><type>bool</type><parameter>case_insensitive</parameter><initializer>&false;</initializer></methodparam>
18
18
</methodsynopsis>
19
19
<para>
20
-
<function>substr_compare</function> compares <parameter>main_str</parameter>
21
-
from position <parameter>offset</parameter> with <parameter>str</parameter>
20
+
<function>substr_compare</function> compares <parameter>haystack</parameter>
21
+
from position <parameter>offset</parameter> with <parameter>needle</parameter>
22
22
up to <parameter>length</parameter> characters.
23
23
</para>
24
24
</refsect1>
...
...
@@ -28,7 +28,7 @@
28
28
<para>
29
29
<variablelist>
30
30
<varlistentry>
31
-
<term><parameter>main_str</parameter></term>
31
+
<term><parameter>haystack</parameter></term>
32
32
<listitem>
33
33
<para>
34
34
The main string being compared.
...
...
@@ -36,7 +36,7 @@
36
36
</listitem>
37
37
</varlistentry>
38
38
<varlistentry>
39
-
<term><parameter>str</parameter></term>
39
+
<term><parameter>needle</parameter></term>
40
40
<listitem>
41
41
<para>
42
42
The secondary string being compared.
...
...
@@ -57,17 +57,17 @@
57
57
<listitem>
58
58
<para>
59
59
The length of the comparison. The default value is the largest of the
60
-
length of the <parameter>str</parameter> compared to the length of
61
-
<parameter>main_str</parameter> minus the
60
+
length of the <parameter>needle</parameter> compared to the length of
61
+
<parameter>haystack</parameter> minus the
62
62
<parameter>offset</parameter>.
63
63
</para>
64
64
</listitem>
65
65
</varlistentry>
66
66
<varlistentry>
67
-
<term><parameter>case_insensitivity</parameter></term>
67
+
<term><parameter>case_insensitive</parameter></term>
68
68
<listitem>
69
69
<para>
70
-
If <parameter>case_insensitivity</parameter> is &true;, comparison is
70
+
If <parameter>case_insensitive</parameter> is &true;, comparison is
71
71
case insensitive.
72
72
</para>
73
73
</listitem>
...
...
@@ -78,14 +78,11 @@
78
78
79
79
<refsect1 role="returnvalues">
80
80
&reftitle.returnvalues;
81
+
&strings.comparison.return;
81
82
<para>
82
-
Returns < 0 if <parameter>main_str</parameter> from position
83
-
<parameter>offset</parameter> is less than <parameter>str</parameter>, >
84
-
0 if it is greater than <parameter>str</parameter>, and 0 if they are equal.
85
83
If <parameter>offset</parameter> is equal to (prior to PHP 7.2.18, 7.3.5) or
86
-
greater than the length of <parameter>main_str</parameter>, or the
84
+
greater than the length of <parameter>haystack</parameter>, or the
87
85
<parameter>length</parameter> is set and is less than 0,
88
-
(or, prior to PHP 5.5.11, less than 1)
89
86
<function>substr_compare</function> prints a warning and returns
90
87
&false;.
91
88
</para>
...
...
@@ -103,10 +100,17 @@
103
100
</row>
104
101
</thead>
105
102
<tbody>
103
+
&standard.changelog.binary-safe-string-comparison;
104
+
<row>
105
+
<entry>8.0.0</entry>
106
+
<entry>
107
+
<parameter>length</parameter> is nullable now.
108
+
</entry>
109
+
</row>
106
110
<row>
107
111
<entry>7.2.18, 7.3.5</entry>
108
112
<entry>
109
-
<parameter>offset</parameter> may now be equal to the length of <parameter>main_str</parameter>.
113
+
<parameter>offset</parameter> may now be equal to the length of <parameter>haystack</parameter>.
110
114
</entry>
111
115
</row>
112
116
</tbody>
...
...
@@ -123,13 +127,13 @@
123
127
<programlisting role="php">
124
128
<![CDATA[
125
129
<?php
126
-
echo substr_compare("abcde", "bc", 1, 2); // 0
127
-
echo substr_compare("abcde", "de", -2, 2); // 0
128
-
echo substr_compare("abcde", "bcg", 1, 2); // 0
129
-
echo substr_compare("abcde", "BC", 1, 2, true); // 0
130
-
echo substr_compare("abcde", "bc", 1, 3); // 1
131
-
echo substr_compare("abcde", "cd", 1, 2); // -1
132
-
echo substr_compare("abcde", "abc", 5, 1); // warning
130
+
echo substr_compare("abcde", "bc", 1, 2), PHP_EOL; // 0
131
+
echo substr_compare("abcde", "de", -2, 2), PHP_EOL; // 0
132
+
echo substr_compare("abcde", "bcg", 1, 2), PHP_EOL; // 0
133
+
echo substr_compare("abcde", "BC", 1, 2, true), PHP_EOL; // 0
134
+
echo substr_compare("abcde", "bc", 1, 3), PHP_EOL; // 1
135
+
echo substr_compare("abcde", "cd", 1, 2), PHP_EOL; // -1
136
+
echo substr_compare("abcde", "abc", 5, 1), PHP_EOL; // -1
133
137
?>
134
138
]]>
135
139
</programlisting>
...
...
@@ -147,7 +151,6 @@ echo substr_compare("abcde", "abc", 5, 1); // warning
147
151
</refsect1>
148
152
149
153
</refentry>
150
-
151
154
<!-- Keep this comment at the end of the file
152
155
Local variables:
153
156
mode: sgml
154
157