php函数stripos详解
stripos — 查找字符串首次出现的位置(不区分大小写)
返回在字符串 haystack 中 needle 首次出现的数字位置。
与 strpos() 不同,stripos() 不区分大小写。
int stripos ( string $haystack , string $needle [, int $offset = 0 ] )
参数
haystack 在该字符串中查找。 needle 注意 needle 可以是一个单字符或者多字符的字符串。 如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符顺序值。 offset 可选的 offset 参数允许你指定从 haystack 中的哪个字符开始查找。返回的位置数字值仍然相对于 haystack 的起始位置。
返回值
返回 needle 存在于 haystack 字符串开始的位置(独立于偏移量)。同时注意字符串位置起始于 0,而不是 1。 如果未发现 needle 将返回 FALSE。
列子:
<?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"; } ?>