You can use the strpos()
function which is used to find the occurrence of one string inside another one:
(您可以使用strpos()
函数来查找另一个字符串中另一个字符串的出现:)
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
Note that the use of !== false
is deliberate (neither != false
nor === true
will return the desired result);
(注意, !== false
的使用是有意的( != false
或=== true
都不会返回期望的结果)。)
strpos()
returns either the offset at which the needle string begins in the haystack string, or the boolean false
if the needle isn't found. (strpos()
返回大海捞针字符串中针串开始的偏移量,或者如果找不到针,则返回布尔值false
。)
Since 0 is a valid offset and 0 is "falsey", we can't use simpler constructs like !strpos($a, 'are')
. (由于0是一个有效的偏移量,而0是“ falsey”,我们不能使用更简单的结构,例如!strpos($a, 'are')
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…