Compare two strings (case sensitive):
<?phpecho strcmp("Hello world!","Hello world!");?>The strcmp() function compares two strings.
Note: The strcmp() function is binary-safe and case-sensitive.
Tip: This function is similar to the strncmp() function, except that with strncmp() you can specify the number of characters for each string to compare.
strcmp( string1,string2 )
parameter | describe |
---|---|
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
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 strcmp("Hello","Hello");echo "<br>";echo strcmp("Hello","hELLo");?>Different return values:
<?phpecho strcmp("Hello world!","Hello world!"); // the two strings are equalecho strcmp("Hello world!","Hello"); // string1 is greater than string2echo strcmp("Hello world !","Hello world! Hello!"); // string1 is less than string2 ?>