函式名:mb_strripos()
適用版本:PHP 4 >= 4.2.0, PHP 5, PHP 7
函式說明:mb_strripos() 函式返回指定字串在另一個字串中最後一次出現的位置(不區分大小寫)。如果未找到該字串,則返回 false。
語法:mb_strripos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|bool
引數:
- $haystack:要在其中查詢的字串。
- $needle:要查詢的字串。
- $offset:可選引數,從字串的指定位置開始搜尋(預設為0)。
- $encoding:可選引數,指定要使用的字元編碼(預設為內部字元編碼)。
返回值:
- 如果找到了指定字串,則返回最後一次出現的位置(以整數形式)。
- 如果未找到指定字串,則返回 false。
示例 1:
$string = "Hello, World!";
$needle = "world";
$position = mb_strripos($string, $needle);
if ($position !== false) {
echo "找到了 needle 在 haystack 中的位置:$position";
} else {
echo "未找到 needle 在 haystack 中";
}
輸出:
找到了 needle 在 haystack 中的位置:7
示例 2:
$string = "Hello, World!";
$needle = "WORLD";
$position = mb_strripos($string, $needle);
if ($position !== false) {
echo "找到了 needle 在 haystack 中的位置:$position";
} else {
echo "未找到 needle 在 haystack 中";
}
輸出:
找到了 needle 在 haystack 中的位置:7
注意事項:
- mb_strripos() 函式是對大小寫不敏感的,可以找到不區分大小寫的匹配項。
- 如果指定了 $offset 引數,則函式將從指定位置開始搜尋。
- 如果指定了 $encoding 引數,則函式將使用指定的字元編碼進行搜尋。
熱門工具排行榜