Home > Article > Backend Development > PHP function that compares the first n characters (case-insensitive) of two strings
Example
Compare two strings (not case sensitive):
<?php echo strncasecmp("Hello world!","hello earth!",6); ?>
Definition and usage
strncasecmp() function compares two string (case-insensitive).
Note: strncasecmp() is binary safe and case-insensitive.
Tips: This function is similar to the strcasecmp() function, except that strcasecmp() has no length parameter.
Syntax
strncasecmp(string1,string2,length)
Parameters | Description |
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
length | Required. Specifies the number of characters per string used for comparison. |
Technical details
Return value: | This function returns:
|
4.0.2+ |
The above is the detailed content of PHP function that compares the first n characters (case-insensitive) of two strings. For more information, please follow other related articles on the PHP Chinese website!