PHP strcasecmp() Function
Example
Compare two strings (case insensitive):
<?php echo strcasecmp("shanghai","SHANGHAI"); ?>
Definition and Usage
The strcasecmp() function compares two strings.
Tip:The strcasecmp() function is binary safe and case-insensitive.
Tip:This function is similar to strncasecmp() Functions are similar, but differently, through strncasecmp() you can specify the number of characters used for comparison in each string.
Syntax
strcasecmp(string1,string2)
Parameters | Description |
---|---|
string1 | Required. Specifies the first string to be compared. |
string2 | Required. Specifies the second string to be compared. |
Technical Details
Return Value: |
The function returns:
|
PHP Version: | 4+ |
More Examples
Example 1
Compare two strings (case-insensitive, HELLO and hELLo output the same):
<?php echo strcasecmp("Shanghai","SHANGHAI"); echo "<br>"; echo strcasecmp("Shanghai","sHANGHai"); ?>
Example 2
Different Return Values:
<?php echo strcasecmp("Hello world!","HELLO WORLD!"); // Two strings are equal echo strcasecmp("Hello world!","HELLO"); // string1 Greater than string2 echo strcasecmp("Hello world!","HELLO WORLD! HELLO!"); // string1 Less than string2 ?>