The strncasecmp() function compares two strings case-insensitive.
Similar to the strcasecmp() function, strncasecmp() has the length parameter.
PHP strncasecmp() Function has the following synax.
strncasecmp(string1,string2,length)
Parameter | Is Required | Description |
---|---|---|
string1 | Required. | First string to compare |
string2 | Required. | Second string to compare |
length | Required. | Number of characters from each string to be used in the comparison |
This function returns:
Compare two strings (case-insensitive):
<?php
echo strncasecmp("Hello world!","hello earth!",6);
?>
The code above generates the following result.
Compare two strings (case-insensitive = Hello and hELLo will output the same):
<?php
echo strncasecmp("Hello","Hello",6);
echo "<br>";
echo strncasecmp("Hello","hELLo",6);
?>
The code above generates the following result.