Example
Compare two strings (case-insensitive):
html
<?php
echo strcasecmp("Hello world!","HELLO WORLD!");
?>
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 the strncasecmp() function, with the difference that you can specify the number of characters from each string to be used in the comparison with strncasecmp().
Syntax
text
strcasecmp(string1,string2)
Parameter Values
| Parameter | Description |
|---|---|
| string1 | Required. Specifies the first string to compare |
| string2 | Required. Specifies the second string to compare |
Technical Details
| Return Value: | This 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+ |
More Examples
Example
Compare two strings (case-insensitive = HELLO and hELLo will output the same):
html
<?php
echo strcasecmp("Hello","HELLO");
echo "<br>";
echo strcasecmp("Hello","hELLo");
?>
Example
Different return values:
html
<?php
echo strcasecmp("Hello world!","HELLO WORLD!"); // The 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
?>