不要直接 if(strpos($mystring, $findme)),这样或导致在第一个字符位置被查找到的字符位置返回0,这样就错了。
要使用 !==false 这样的判断,注意是两个==
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// 使用 !== 操作符。使用 != 不能像我们期待的那样工作,
// 因为 'a' 的位置是 0。语句 (0 != false) 的结果是 false。
if ($pos !== false) {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
} else {
echo "The string '$findme' was not found in the string '$mystring'";
}
?>