2014-09-05 07:44:07 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 09:08:43 +00:00
|
|
|
<!-- $Revision$ -->
|
2020-12-05 14:30:42 +00:00
|
|
|
<refentry xml:id="function.substr-compare" xmlns="http://docbook.org/ns/docbook">
|
2007-06-15 19:01:26 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>substr_compare</refname>
|
2010-03-15 09:20:18 +00:00
|
|
|
<refpurpose>Binary safe comparison of two strings from an offset, up to length characters</refpurpose>
|
2007-06-15 19:01:26 +00:00
|
|
|
</refnamediv>
|
2007-06-15 19:01:57 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-06-15 19:01:26 +00:00
|
|
|
<methodsynopsis>
|
2020-11-28 17:58:32 +00:00
|
|
|
<type>int</type><methodname>substr_compare</methodname>
|
2020-12-05 14:30:42 +00:00
|
|
|
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
|
|
|
|
<methodparam><type>string</type><parameter>needle</parameter></methodparam>
|
2007-06-15 19:01:26 +00:00
|
|
|
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
|
2020-12-05 14:30:42 +00:00
|
|
|
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>case_insensitive</parameter><initializer>&false;</initializer></methodparam>
|
2007-06-15 19:01:26 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2020-12-05 14:30:42 +00:00
|
|
|
<function>substr_compare</function> compares <parameter>haystack</parameter>
|
|
|
|
from position <parameter>offset</parameter> with <parameter>needle</parameter>
|
2007-06-15 19:01:26 +00:00
|
|
|
up to <parameter>length</parameter> characters.
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2020-12-05 14:30:42 +00:00
|
|
|
<term><parameter>haystack</parameter></term>
|
2007-06-15 19:01:57 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-08 09:29:30 +00:00
|
|
|
The main string being compared.
|
2007-06-15 19:01:57 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-12-05 14:30:42 +00:00
|
|
|
<term><parameter>needle</parameter></term>
|
2007-06-15 19:01:57 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-08 09:29:30 +00:00
|
|
|
The secondary string being compared.
|
2007-06-15 19:01:57 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>offset</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2007-09-01 18:57:54 +00:00
|
|
|
The start position for the comparison. If negative, it starts counting
|
|
|
|
from the end of the string.
|
2007-06-15 19:01:57 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>length</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2010-02-11 11:18:34 +00:00
|
|
|
The length of the comparison. The default value is the largest of the
|
2020-12-05 14:30:42 +00:00
|
|
|
length of the <parameter>needle</parameter> compared to the length of
|
|
|
|
<parameter>haystack</parameter> minus the
|
2010-02-11 11:18:34 +00:00
|
|
|
<parameter>offset</parameter>.
|
2007-06-15 19:01:57 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2020-12-05 14:30:42 +00:00
|
|
|
<term><parameter>case_insensitive</parameter></term>
|
2007-06-15 19:01:57 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-12-05 14:30:42 +00:00
|
|
|
If <parameter>case_insensitive</parameter> is &true;, comparison is
|
2007-06-15 19:01:57 +00:00
|
|
|
case insensitive.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
2020-12-05 14:30:42 +00:00
|
|
|
Returns < 0 if <parameter>haystack</parameter> from position
|
|
|
|
<parameter>offset</parameter> is less than <parameter>needle</parameter>, >
|
|
|
|
0 if it is greater than <parameter>needle</parameter>, and 0 if they are equal.
|
2019-05-02 14:12:29 +00:00
|
|
|
If <parameter>offset</parameter> is equal to (prior to PHP 7.2.18, 7.3.5) or
|
2020-12-05 14:30:42 +00:00
|
|
|
greater than the length of <parameter>haystack</parameter>, or the
|
2019-05-02 14:12:29 +00:00
|
|
|
<parameter>length</parameter> is set and is less than 0,
|
2014-08-28 05:47:47 +00:00
|
|
|
<function>substr_compare</function> prints a warning and returns
|
2009-12-08 09:29:30 +00:00
|
|
|
&false;.
|
2007-06-15 19:01:26 +00:00
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
2007-09-01 18:57:54 +00:00
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
|
|
|
<para>
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2020-12-05 14:30:42 +00:00
|
|
|
<row>
|
|
|
|
<entry>8.0.0</entry>
|
|
|
|
<entry>
|
|
|
|
<parameter>length</parameter> is nullable now.
|
|
|
|
</entry>
|
|
|
|
</row>
|
2019-05-02 14:12:29 +00:00
|
|
|
<row>
|
|
|
|
<entry>7.2.18, 7.3.5</entry>
|
|
|
|
<entry>
|
2020-12-05 14:30:42 +00:00
|
|
|
<parameter>offset</parameter> may now be equal to the length of <parameter>haystack</parameter>.
|
2019-05-02 14:12:29 +00:00
|
|
|
</entry>
|
|
|
|
</row>
|
2007-09-01 18:57:54 +00:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-06-15 19:01:57 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>A <function>substr_compare</function> example</title>
|
|
|
|
<programlisting role="php">
|
2004-04-26 17:43:26 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
echo substr_compare("abcde", "bc", 1, 2); // 0
|
2007-09-01 18:57:54 +00:00
|
|
|
echo substr_compare("abcde", "de", -2, 2); // 0
|
2004-04-26 17:43:26 +00:00
|
|
|
echo substr_compare("abcde", "bcg", 1, 2); // 0
|
|
|
|
echo substr_compare("abcde", "BC", 1, 2, true); // 0
|
|
|
|
echo substr_compare("abcde", "bc", 1, 3); // 1
|
|
|
|
echo substr_compare("abcde", "cd", 1, 2); // -1
|
|
|
|
echo substr_compare("abcde", "abc", 5, 1); // warning
|
|
|
|
?>
|
|
|
|
]]>
|
2007-06-15 19:01:26 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-06-15 19:01:57 +00:00
|
|
|
|
2012-07-19 22:46:06 +00:00
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
|
|
|
<member><function>strncmp</function></member>
|
|
|
|
</simplelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-06-15 19:01:26 +00:00
|
|
|
</refentry>
|
2003-11-02 16:48:28 +00:00
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2003-11-02 16:48:28 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|