How to use php character comparison strcmp() function_PHP tutorial

WBOY
Release: 2016-07-13 17:15:02
Original
1429 people have browsed it

The strcmp() function is used to compare two strings. If the two strings are completely equal, we will return 0, otherwise there will be various return values. This function is not case-sensitive. Friends in need can refer to it. .

Explanation of return value after comparison

If str1 and str2 are equal, return 0.
If str1 is less than str2, it returns <0 (but not necessarily -1. Many people on the Internet say it is -1, which is wrong. The specific value depends on the actual situation).
If str1 is greater than str2, it returns >0 (but not necessarily 1, the specific value depends on the actual situation).

Example

The code is as follows
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
代码如下 复制代码

strcmp(date(‘Y-m-d’,$user->last_time), date(“Y-m-d”,time())) == 0

Copy code

strcmp(date(‘Y-m-d’,$user->last_time), date(“Y-m-d”,time())) == 0

 代码如下 复制代码

echo strncasecmp("abcdd", "abcde", 3);

If you don’t want to distinguish between uppercase and lowercase letters

 代码如下 复制代码

$a='aa';
$b='www.bKjia.c0m';

if( $a == $b )
{
 echo '相等';
}
else
{
echo '不等';
}

strncasecmp is used to compare part of a string in a case-insensitive manner, starting from the beginning of the string. The third parameter is the length to be compared:

echo strncasecmp("abcdd", "abcde", 3);
The code is as follows Copy code
 代码如下 复制代码

22 == "22"; // 返回 true
22 === "22"; // 返回false

We can also use == to compare PHP strings, such as
The code is as follows Copy code
$a='aa'; $b='www.bKjia.c0m'; if( $a == $b ) { echo 'Equal'; } else
{
echo 'not equal'; } You can also use === to compare
The code is as follows Copy code
22 == "22"; // returns true 22 === "22"; // return false http://www.bkjia.com/PHPjc/628890.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628890.htmlTechArticleThe strcmp() function is used to compare two strings. If the two strings are completely equal, we will return 0 , otherwise there will be various return values. This function is not case-sensitive. Friends in need can refer to...