Home >>PHP String Functions >PHP strncasecmp() Function
PHP strncasecmp() function is used to compare two given input strings. It is case-insensitive. It is similar to strcasecmp() function but the only difference is that strcasecmp() function doesn’t have the length parameter.
Syntax:
strncasecmp($string1, $string2, $length);
Parameter | Description |
---|---|
string1 | This is a required parameter. This parameter defines the first string to compare. |
string2 | This is a required parameter. This parameter defines the second string to compare. |
length | This is a required parameter. This parameter defines the number of characters from each string to be used in the comparison. |
Here is an example of strncasecmp() function in PHP:
<html> <body> <?php echo strncasecmp("PhpTpoint","PHPTPOINT..",8); // returns zero when both the strings are same. ?> </body> </html>
Here is an another example of strncasecmp() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo strncasecmp($str,"php",2); // case insensitive echo "<br>"; echo strncasecmp($str,"PHP",2); echo "<br>"; echo strncasecmp($str,"phpT",3); echo "<br>"; echo strncasecmp($str,"phpT",7); // first string is greater than second string. ?> </body> </html>