如果未发现 needle,stripos() 将返回布尔型 FALSE。
Warning
此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值,例如 0 或 ""(空串)。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符 来测试此函数的返回值。
范例
Example #1 stripos() 范例
<?php
$findme = 'a';
$mystring1 = 'xyz';
$mystring2 = 'ABC';
$pos1 = stripos($mystring1, $findme);
$pos2 = stripos($mystring2, $findme);
// 'a' 当然不在 'xyz' 中
if ($pos1 === false) {
echo "The string '$findme' was not found in the string '$mystring1'";
}
// 注意这里使用的是 ===。简单的 == 不能像我们期望的那样工作,
// 因为 'a' 的位置是 0(第一个字符)。
if ($pos2 !== false) {
echo "We found '$findme' in '$mystring2' at position $pos2";
}
?>