strncasecmp – PHP String Functions
Syntax :
Description :
strncasecmp() function will compare two strings.
Note : Binary safe case-insensitive string comparison function.
Parameter :
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description
string1, Required, String, It is the first string which will be compared.
string2, Required, String, It is the second string which will be compared.
length, Required, integer, It specifies the number of characters from each string to be used in the comparison.
[/table]
Output :
Return values in this function are:
- 0 – if the two strings are equal.
- < 0 – if string1 is less than string2.
- > 0 – if string1 is greater than string2.
Related articles : substr_compare(), strcasecmp(), stristr(), substr() .
strncasecmp() – PHP Functions Example 1 : It returns 0, if the two strings are equal.
<?php // case-insensitive comparison echo strncasecmp("Hi from tutorialmines.","hI FROM TUTORIALMINES.",10); ?>
Output of above code in the browser is as below:
strncasecmp() – PHP Functions Example 2 : It returns 0, if the two strings are equal. Case of character does not matter for it.
<?php echo strncasecmp("Hi from tutorialmines.","hI FROM TUTORIALMINES."); echo "<br/>"; echo strncasecmp("Hi from tutorialmines.","hI from Tutorialmines."); ?>
Output of above code in the browser is as below:
0