Files
doc-en/reference/strings/functions/strncmp.xml
Chris Brown 43cc4ed372 strncmp: Correct minor typo in example (#3768)
`are equals` vs `are equal`
2024-09-21 15:31:50 -07:00

142 lines
3.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.strncmp" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>strncmp</refname>
<refpurpose>Binary safe string comparison of the first n characters</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>strncmp</methodname>
<methodparam><type>string</type><parameter>string1</parameter></methodparam>
<methodparam><type>string</type><parameter>string2</parameter></methodparam>
<methodparam><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
This function is similar to <function>strcmp</function>, with the
difference that you can specify the (upper limit of the) number of
characters from each string to be used in the comparison.
</para>
<para>
Note that this comparison is case sensitive.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>string1</parameter></term>
<listitem>
<para>
The first string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>string2</parameter></term>
<listitem>
<para>
The second string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>length</parameter></term>
<listitem>
<para>
Number of characters to use in the comparison.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns <literal>-1</literal> if <parameter>string1</parameter> is less than
<parameter>string2</parameter>; <literal>1</literal> if <parameter>string1</parameter>
is greater than <parameter>string2</parameter>, and <literal>0</literal> if they are
equal.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
&standard.changelog.binary-safe-string-comparison;
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>strncmp</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$var1 = 'Hello John';
$var2 = 'Hello Doe';
if (strncmp($var1, $var2, 5) === 0) {
echo 'First 5 characters of $var1 and $var2 are equal in a case-sensitive string comparison';
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>strncasecmp</function></member>
<member><function>preg_match</function></member>
<member><function>substr_compare</function></member>
<member><function>strcmp</function></member>
<member><function>strstr</function></member>
<member><function>substr</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- 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
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
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
-->