PHP » Strings » strnatcasecmp()

Syntax:
int strnatcasecmp(string s1, string s2)
s1
The first string.
s2
The second string.

Case insensitive natural comparison of two strings.

This function works just like strnatcmp(), but is case insensitive.

Examples

Code:
<?php

$s1 = "document10";
$s2 = "document2";
$s3 = "DOCUMENT2";

if (strnatcasecmp($s1, $s2) < 0) {
   print "$s1 is smaller than $s2<br>";
} else {
   print "$s2 is smaller than $s1<br>";
}

if (strnatcasecmp($s2, $s3) == 0) {
   print "$s2 is equal to $s3<br>";
} else {
   print "$s2 and $s3 are not equal<br>";
}

?>
Output:
document2 is smaller than document10
document2 is equal to DOCUMENT2
Explanation:

The strings are compared in natural order and lower and upper case characters are valued equally.

See Also: