mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00
Added url for the "natural order" string comparison algorithm, and
documentation (w/ example) for strnatcmp and strnatordercmp git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@30656 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
3feb92cd34
commit
e2b2a639e6
1 changed files with 170 additions and 4 deletions
|
@ -1755,7 +1755,7 @@ $formatted = sprintf ("%01.2f", $money);
|
|||
</funcsynopsis>
|
||||
<para>
|
||||
Returns < 0 if <parameter>str1</parameter> is less than
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
is greater than <parameter>str2</parameter>, and 0 if they are
|
||||
equal.
|
||||
<example>
|
||||
|
@ -1816,7 +1816,7 @@ if (!strcasecmp ($var1, $var2)) {
|
|||
</funcsynopsis>
|
||||
<simpara>
|
||||
Returns < 0 if <parameter>str1</parameter> is less than
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
is greater than <parameter>str2</parameter>, and 0 if they are
|
||||
equal.
|
||||
</simpara>
|
||||
|
@ -1826,7 +1826,8 @@ if (!strcasecmp ($var1, $var2)) {
|
|||
<simpara>
|
||||
See also <function>ereg</function>,
|
||||
<function>strcasecmp</function>, <function>substr</function>,
|
||||
<function>stristr</function>, and <function>strstr</function>.
|
||||
<function>stristr</function>, <function>strncmp</function>,
|
||||
and <function>strstr</function>.
|
||||
</simpara>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
@ -2006,6 +2007,171 @@ if (!strcasecmp ($var1, $var2)) {
|
|||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.strnatcmp">
|
||||
<refnamediv>
|
||||
<refname>strnatcmp</refname>
|
||||
<refpurpose>
|
||||
String comparisons using a "natural order" algorithm
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>strnatcmp</function></funcdef>
|
||||
<paramdef>string <parameter>str1</parameter></paramdef>
|
||||
<paramdef>string <parameter>str2</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This function implements a comparison algorithm that orders
|
||||
alphanumeric strings in the way a human being would, this is
|
||||
described as a "natural ordering". An example of the difference
|
||||
between this algorithm and the regular computer string sorting
|
||||
algorithms (used in <function>strcmp</function>) can be seen
|
||||
below:
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
$arr1 = $arr2 = array ("img12.png","img10.png","img2.png","img1.png");
|
||||
echo "Standard string comparison\n";
|
||||
usort($arr1,"strcmp");
|
||||
print_r($arr1);
|
||||
echo "\nNatural order string comparison\n";
|
||||
usort($arr2,"strnatcmp");
|
||||
print_r($arr2);
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
The code above will generate the following output:
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
Standard string comparison
|
||||
Array
|
||||
(
|
||||
[0] => img1.png
|
||||
[1] => img10.png
|
||||
[2] => img12.png
|
||||
[3] => img2.png
|
||||
)
|
||||
|
||||
Natural order string comparison
|
||||
Array
|
||||
(
|
||||
[0] => img1.png
|
||||
[1] => img2.png
|
||||
[2] => img10.png
|
||||
[3] => img12.png
|
||||
)
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
For more infomation see: Martin Pool's <ulink
|
||||
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
|
||||
page.
|
||||
</para>
|
||||
<simpara>
|
||||
Similar to other string comparison functions, this one returns
|
||||
< 0 if <parameter>str1</parameter> is less than
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
is greater than <parameter>str2</parameter>, and 0 if they are
|
||||
equal.
|
||||
</simpara>
|
||||
<simpara>
|
||||
Note that this comparison is case sensitive.
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <function>ereg</function>,
|
||||
<function>strcasecmp</function>, <function>substr</function>,
|
||||
<function>stristr</function>, <function>strcmp</function>,
|
||||
<function>strncmp</function>, <function>strnatcasecmp</function>,
|
||||
and <function>strstr</function>.
|
||||
</simpara>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.strnatcasecmp">
|
||||
<refnamediv>
|
||||
<refname>strnatcasecmp</refname>
|
||||
<refpurpose>
|
||||
Case insensitive string comparisons using a "natural order" algorithm
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>strnatcasecmp</function></funcdef>
|
||||
<paramdef>string <parameter>str1</parameter></paramdef>
|
||||
<paramdef>string <parameter>str2</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This function implements a comparison algorithm that orders
|
||||
alphanumeric strings in the way a human being would. The
|
||||
behavior of this function is similar to
|
||||
<function>strnatcomp</function>, except that the comparison is
|
||||
not case sensitive. For more infomation see: Martin Pool's
|
||||
<ulink url="&url.strnatcmp;">Natural Order String
|
||||
Comparison</ulink> page.
|
||||
</para>
|
||||
<simpara>
|
||||
Similar to other string comparison functions, this one returns
|
||||
< 0 if <parameter>str1</parameter> is less than
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
is greater than <parameter>str2</parameter>, and 0 if they are
|
||||
equal.
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <function>ereg</function>,
|
||||
<function>strcasecmp</function>, <function>substr</function>,
|
||||
<function>stristr</function>, <function>strcmp</function>,
|
||||
<function>strncmp</function>, <function>strnatcmp</function>,
|
||||
and <function>strstr</function>.
|
||||
</simpara>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.strncmp">
|
||||
<refnamediv>
|
||||
<refname>strncmp</refname>
|
||||
<refpurpose>
|
||||
Binary safe string comparison of the first n characters
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>int <function>strncmp</function></funcdef>
|
||||
<paramdef>string <parameter>str1</parameter></paramdef>
|
||||
<paramdef>string <parameter>str2</parameter></paramdef>
|
||||
<paramdef>int <parameter>len</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This function is similar to <function>strcmp</function>, with the
|
||||
difference that you can specify the (upper limit of the) number of
|
||||
characters (<parameter>len</parameter>) from each string to be
|
||||
used in the comparison. If any of the strings is shorter than
|
||||
<parameter>len</parameter>, then the length of that string will be
|
||||
used for the comparison.
|
||||
</para>
|
||||
<simpara>
|
||||
Returns < 0 if <parameter>str1</parameter> is less than
|
||||
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
||||
is greater than <parameter>str2</parameter>, and 0 if they are
|
||||
equal.
|
||||
</simpara>
|
||||
<simpara>
|
||||
Note that this comparison is case sensitive.
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <function>ereg</function>,
|
||||
<function>strcasecmp</function>, <function>substr</function>,
|
||||
<function>stristr</function>, <function>strcmp</function>,
|
||||
and <function>strstr</function>.
|
||||
</simpara>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.str-pad">
|
||||
<refnamediv>
|
||||
<refname>str_pad</refname>
|
||||
|
@ -2583,7 +2749,7 @@ $addr = strtr($addr, "
|
|||
Examples:
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
$trans = array ("hello" => "hi", "hi" => "hello");
|
||||
$trans = array ("hello" => "hi", "hi" => "hello");
|
||||
echo strtr("hi all, I said hello", $trans) . "\n";
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
|
Loading…
Reference in a new issue