PHP strncmp()Functions
Examples
Compare two strings (case-sensitive):
<?php
echo strncmp("Hello world!","Hello earth!",6);
?>
echo strncmp("Hello world!","Hello earth!",6);
?>
Run example »
Definition and Usage
The strncmp() function compares two strings (case-sensitive).
Note:strncmp() is binary-safe and case-sensitive.
Tip:This function is similar tostrcmp()the function, except that strcmp() does not have the length parameter.
Syntax
strncmp(string1,string2,length)
| Parameter | Description |
|---|---|
| string1 | Required. Specifies the first string to compare. |
| string2 | Required. Specifies the second string to compare. |
| length | Required. Specifies the number of characters from each string to compare. |
Technical Details
| Return value: | This function returns:
|
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Compare two strings (case-sensitive, Hello and hELLo output are different):
<?php
echo strncmp("Hello","Hello",6);
echo "<br>";
echo strncmp("Hello","hELLo",6);
?>
echo strncmp("Hello","Hello",6);
echo "<br>";
echo strncmp("Hello","hELLo",6);
?>
Run example »
PHP String Reference Manual Other Extensions