Php character comparison strcmp () function usage method. The strcmp () function compares two strings. if the two strings are completely equal, 0 is returned. otherwise, various return values are returned. This function is case sensitive, if you need a friend, you can use the strcmp () function to compare two strings. if the two strings are completely equal, 0 is returned. otherwise, various return values are returned. This function is case sensitive, for more information, see.
Return value after Comparison
If str1 and str2 are equal, 0 is returned.
If str1 is smaller than str2, return <0 (but not necessarily scheduled-1, many online saying-1, is incorrect, the specific value size depends on the actual situation ).
If str1 is greater than str2, return> 0 (but different timing 1, the specific value size depends on the actual situation ).
Example
| The code is as follows: |
|
|
Strcmp (date ('Y-m-D', $ user-> last_time), date ("Y-m-d", time () = 0 |
If case insensitive
Strncasecmp is used to compare a part of a case-insensitive string. it starts from the beginning of the string and the third parameter is the length to be compared:
| The code is as follows: |
|
|
Echo strncasecmp ("abcdd", "abcde", 3 ); |
// Return 0, which compares abc and abc. The two are the same because they are case insensitive.
We can also use = to compare php strings, as shown in
| The code is as follows: |
|
|
$ A = 'a ';
$ B = 'www. bKjia. c0m ';
If ($ a = $ B)
{
Echo 'Equality ';
}
Else
{
Echo 'unequal ';
} |
You can also use = to compare
| The code is as follows: |
|
|
22 = "22"; // return true
22 = "22"; // Return false |
The use of the http://www.bkjia.com/PHPjc/628890.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/628890.htmlTechArticlestrcmp () function is to compare two strings, if the two strings are completely equal we will return 0, otherwise there will be a variety of return values, this function is case sensitive, if you need a friend, you can take the parameter...