Compare two strings (case insensitive):
<?phpecho strcasecmp("Hello world!","HELLO WORLD!");?>The strcasecmp() function compares two strings.
Tip: The strcasecmp() function is binary-safe and case-insensitive.
Tip: This function is similar to the strncasecmp() function, except that with strncasecmp() you can specify the number of characters for each string to compare.
strcasecmp( string1,string2 )
parameter | describe |
---|---|
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
Return value: | The function returns: 0 - if the two strings are equal <0 - if string1 is less than string2 >0 - if string1 is greater than string2 |
---|---|
PHP version: | 4+ |
Compare two strings (case insensitive, HELLO and hELLo output the same):
<?phpecho strcasecmp("Hello","HELLO");echo "<br>";echo strcasecmp("Hello","hELLo");?>Different return values:
<?phpecho strcasecmp("Hello world!","HELLO WORLD!"); // The two strings are equalecho strcasecmp("Hello world!","HELLO"); // String1 is greater than string2echo strcasecmp("Hello world !","HELLO WORLD! HELLO!"); // String1 is less than string2 ?>