PHP determines whether a string contains the specified string

There are two ways to use the string search functions strstr() and strpos()
strstr() function -> Find the first occurrence of the specified string and return the remaining part of the string:
strpos() function -> Find the first occurrence of the specified string (starting from 0)
It is recommended here to use the strpos() function, which is faster and consumes less memory (case-sensitive, use stripos() if case-insensitive)
$str = 'hello china ~';
$checkstr = 'hello';
// 这里判断必须用双等号 !== 才有效果,因为可能返回等同false的布尔值
if (strpos($str, $checkstr) !== false) {
    
    
    die('恭喜你查询到了');
}else{
    
    
    die('查询不到');
}

Guess you like

Origin blog.csdn.net/qq_15957557/article/details/124445053