办法1
<?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作, // 因为 'a' 是第 0 位置上的(第一个)字符。 if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } ?>
办法1
<?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'"; } ?>