Compare two strings (case sensitive):
<?phpecho strncmp("Hello world!","Hello earth!",6);?>The strncmp() function compares two strings (case sensitive).
Note: strncmp() is binary-safe and case-sensitive.
Tip: This function is similar to the strcmp() function, except that strcmp() does not have a length parameter.
strncmp( string1,string2,length )
parameter | describe |
---|---|
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. |
Return value: | The function returns: 0 - if the two strings are equal <0 - if string1 is less than string2 >0 - if string1 is greater than string2 |
---|---|
PHP version: | 4+ |
Compare two strings (case sensitive, Hello and hELLo output are not the same):
<?phpecho strncmp("Hello","Hello",6);echo "<br>";echo strncmp("Hello","hELLo",6);?>