PHP strncmp() Function
Example
Compare Two Strings (Case Sensitive):
<?php echo strncmp("I love China!","I love Shanghai!",6); ?>
Definition and Usage
The strncmp() function compares two strings.
Note:strncmp() is binary safe and case sensitive.
Tip:This function is similar to strcmp() The function is similar, but strcmp() does not have length Parameters.
Syntax
strncmp(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 used in each string for the comparison. |
Technical Details
Return Value: |
This function returns:
|
PHP Version: | 4+ |
More Examples
Example 1
Compare Two Strings (Case Sensitive, Output is different for 'China' and 'CHINA'):
<?php echo strncmp("China","China",6); echo "<br>"; echo strncmp("China","CHINA",6); ?>