(PHP 5, PHP 7, PHP 8)
strripos — 計算指定字符串在目標字符串中最后一次出現的位置(不區分大小寫(xiě))
$haystack
, string $needle
, int $offset
= 0): int以不區分大小寫(xiě)的方式查找指定字符串在目標字符串中最后一次出現的位置。與 strrpos() 不同,strripos() 不區分大小寫(xiě)。
haystack
在此字符串中進(jìn)行查找。
needle
注意 needle
可以是一個(gè)單字符或者多字符的字符串。
offset
參數 offset
可以被指定來(lái)查找字符串中任意長(cháng)度的子字符串。
負數偏移量將使得查找從字符串的起始位置開(kāi)始,到 offset
位置為止。
返回 needle 相對于 haystack
字符串的位置(和搜索的方向和偏移量無(wú)關(guān))。同時(shí)注意字符串的起始位置為 0 而非 1。
如果 needle 未被發(fā)現,返回 false
。
示例 #1 strripos() 簡(jiǎn)單范例
<?php
$haystack = 'ababcd';
$needle = 'aB';
$pos = strripos($haystack, $needle);
if ($pos === false) {
echo "Sorry, we did not find ($needle) in ($haystack)";
} else {
echo "Congratulations!\n";
echo "We found the last ($needle) in ($haystack) at position ($pos)";
}
?>
以上例程會(huì )輸出:
Congratulations! We found the last (aB) in (ababcd) at position (2)