Home >>PHP String Functions >PHP strcasecmp() Function
PHP strcasecmp() function is used to compare two given strings. It is case-insensitive and binary-safe. It is similar to PHP strncasecmp() function but it specify the number of characters to be used from each string for the comparison.
Syntax:
strcasecmp($string1, $string2);
Parameter | Description |
---|---|
string1 | This is a required parameter. This parameter contains the first string to compare. |
string2 | This is a required parameter. This parameter contains the second string to compare. |
Here is an example of strcasecmp() function in PHP:
<html> <body> <?php $str1 = "PHPTPOINT"; $str2 = "PhpTpoint"; echo strcasecmp($str1,$str2); //return value 0 means both string are same ?> </body> </html>
Here is an example of strcasecmp() function in PHP:
<html> <body> <?php $str1 = "Hello Everyone.."; $str2 = "Hello Everyone.. I am Jerry."; echo strcasecmp($str1,"hElLo evErYoNE..")."<br>"; // Both strings are equal echo strcasecmp($str2,$str1)."<br>"; // 1st string is greater than 2nd echo strcasecmp($str1,$str2)."<br>"; // 1st string is less than 2nd ?> </body> </html>