English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The strcasecmp() function is used to compare two strings (case-insensitive)
int strcasecmp ( string $str1 , string $str2 )
Used to compare two strings
Note: The strcasecmp() function is binary safe and case-insensitive.
If str1 is less than str2 Returns < 0; if str1 Greater than str2 Returns > 0; if both are equal, returns 0.
Number | Parameter and Description |
---|---|
1 | str1 Required. The first string |
2 | str2 Required. The second string |
Try the following example to compare two strings, case-insensitive, and return the comparison result:
<?php //Compare two strings (case-insensitive, Hello and HELlo output the same) echo strcasecmp("Hello WORLD!","HELlo PHP!"); echo '<br>'; $var1 = "Hello"; $var2 = "heLLO"; if (strcasecmp($var1, $var2) == 0) { echo 'In case-insensitive string comparison, $var1equals $var2'; } ?>Test and see‹/›
Output result
7 In case-insensitive string comparison, $var1equals $var2