Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串$x = 'hello world.'。我想看看 $x 是否包含 string $y = 'hello'。
$x = 'hello world.'
$y = 'hello'
如果我做
stripos($x, $y);
它返回一个数字 0,即字符串 $y 开始的索引。然而,这评估为 FALSE。我如何评估它以使其返回 true?
阅读手册中的警告通知:
警告:此函数可能返回布尔值 FALSE,但也可能返回计算结果为 FALSE 的非布尔值。请阅读有关布尔值的部分以获取更多信息。使用===操作符来测试这个函数的返回值。
===
所以你应该这样使用:
if(stripos($x, $y) !== FALSE) // Found else // Not found
有关参考,请参阅手册中的此示例。
如果你使用它,它将返回 true
!(stripos($x, $y)); $x = 'hello world.'; $y = 'hello'; echo !(stripos($x, $y));