Instance
Compare two strings (case insensitive):
<?phpecho strcasecmp ("Hello world!", "Hello world!");? >
Definition and usage
The strcasecmp () function compares two strings.
Tip: the strcasecmp () function is binary safe and is case-insensitive.
Tip: This function is similar to the strncasecmp () function, but by strncasecmp () you can specify the number of characters each string is used to compare.
Grammar
STRCASECMP (STRING1,STRING2)
Parameters |
Describe |
String1 |
Necessary. Specifies the first string to compare. |
string2 |
Necessary. Specifies a second string to compare. |
Technical details
return value: |
This function returns:
-
0-if two strings are equal
-
<0-if string1 is less than string2
-
>0-if string1 is greater than string2
|
php version: |
4+ |
More examples
Example 1
Compare two strings (case insensitive, hello and hello output are the same):
<?phpecho strcasecmp ("Hello", "Hello"), echo "<br>", Echo strcasecmp ("Hello", "Hello"); >
Example 2
Different return values:
<?phpecho strcasecmp ("Hello world!", "Hello world!"); The strings is Equalecho strcasecmp ("Hello world!", "Hello"); String1 is greater than String2echo strcasecmp ("Hello world!", "Hello world! Hello! "); String1 is less than string2?>
strcasecmp-binary Security comparison string (case insensitive)
int strcasecmp (String $str 1, String $str 2)
return value:
Returns a negative number if the str1 is less than str2, returns a positive number if the STR1 is greater than str2, and returns 0 if they are equal.
Simple example:
<?php$var1 = "Hello"; $var 2 = "Hello"; if (strcasecmp ($var 1, $var 2) = = 0) { echo ' $var 1 is equal to $var 2 in a case-i Nsensitive string comparison ';}? >