strcasecmp
Binary safe case-insensitive string comparison
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, except that with strncasecmp() you can specify the number of characters each string is used for comparison.
Compare two strings (case insensitive):
<?php echo strcasecmp ( "shanghai" , "SHANGHAI" ) ; ?>
Try it yourself
Comparison of two strings (case insensitive, HELLO and hELLo outputs are the same):
<?php echo strcasecmp ( "Shanghai" , "SHANGHAI" ) ; echo "<br>" ; echo strcasecmp ( "Shanghai" , "sHANGHai" ) ; ?>
Try it yourself
Different return values:
<?php echo strcasecmp ( "Hello world!" , "HELLO WORLD!" ) ; // Two strings are equal echo strcasecmp ( "Hello world!" , "HELLO" ) ; // string1 is greater than string2 echo strcasecmp ( "Hello world!" , "HELLO WORLD! HELLO!" ) ; // string1 is less than string2 ?>
Try it yourself
strcasecmp ( string1 , string2 )
| parameter | describe |
|---|---|
| string1 | Required. Specifies the first string to be compared. |
| string2 | Required. Specifies the second string to be compared. |