PHP strncmp() Function
Example
Compare two strings (case-sensitive):
Run Example »
Definition and Usage
The strncmp() function compares two strings (case-sensitive).
**Note:** strncmp() is binary-safe and case-sensitive.
**Tip:** The difference between this function and strcmp() The strncmp() function is similar, except that strcmp() has no length parameter.
Syntax
strncmp(
string1,string2,length
)
| Parameters | Description |
|---|---|
| string1 | Required. Specifies the first string to compare. |
| string2 | Required. Specifies the second string to compare. |
| length | Required. Specifies the number of characters of each string to compare. |
Technical Details
| Return value: | This function returns:
- 0 - If the two strings are equal
- <0 - If string1 is less than string2
- >0 - If string1 is greater than string2
More examples
Example 1
Compare two strings (case-sensitive, Hello and hELLo produce different output):
"; echo strncmp("Hello","hELLo",6); ?>Run Example »
PHP String Reference Manual