Case insensitive comparison of two strings.
This function works like strcmp(), but is case insensitive. If the first string is "smaller", in the sorting sense, -1 is returned. 1 is returned if the the first string is larger in value.
<?php
$s1 = "abc";
$s2 = "def";
$s3 = "XYZ";
$s4 = "ABC";
if (strcasecmp($s1, $s2) < 0) {
print "$s1 is smaller than $s2<br>";
} else {
print "$s2 is smaller than $s1<br>";
}
if (strcasecmp($s1, $s3) < 0) {
print "$s1 is smaller than $s3<br>";
} else {
print "$s3 is smaller than $s1<br>";
}
if (strcasecmp($s1, $s4) == 0) {
print "$s1 is equal to $s4";
} else {
print "$s1 and $s4 are not equal";
}
?>
abc is smaller than def
abc is smaller than XYZ
abc is equal to ABC
Despite different ASCII values, lower and upper case characters are valued equally.