PHP strncasecmp() Function
Example
Compare two strings (case-insensitive):
<?php echo strncasecmp("I love China!","I love Shanghai!",6); ?>
Definition and Usage
strncasecmp() function compares two strings.
Note:strncasecmp() is binary safe and case-insensitive.
Tip:This function is similar to strcasecmp() The function is similar, but different from strcasecmp(), it does not have length Parameters.
Syntax
strncasecmp(string1, string2,length)
Parameters | Description |
---|---|
string1 | Required. Specifies the first string to be compared. |
string2 | Required. Specifies the second string to be compared. |
length | Required. Specifies the number of characters to be compared in each string. |
Technical Details
Return value: |
This function returns:
|
PHP Version: | 4+ |
More Examples
Example 1
Compare two strings (case-insensitive, China and CHINA output the same):
<?php echo strncasecmp("China","China",6); echo "<br>"; echo strncasecmp("China","CHINA",6); ?>