strripos() 是 PHP 的預定義字符串函數。它用於查找一個字符串在另一個字符串中最後一次出現的位置。
用法:
Strripos(string,find,start);
參數 | 描述 | 必需/可選 |
---|---|---|
String | 指定要搜索的字符串。 | Required |
Find | 指定要查找的字符串。 | Required |
Start | 指定從何處開始搜索。 | Optional |
函數 strripos() 返回字符串最後一次出現的位置。如果未找到字符串,則為 FALSE。字符串位置從 0 而不是 1 開始。
注意:strripos() 函數不區分大小寫。
例子1
<?php
echo "By using 'strripos()' function:".strripos("Hello php,Hello php and Javascript!","PHP")
?>
輸出:
By using 'strripos()' function:16
例子2
<?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)";
}
?>
輸出:
Congratulations! We found the last (aB) in (ababcd) at position (2)
另見:
- stripos():它用於返回一個字符串在另一個字符串中第一次出現的位置。
- strpos():它用於返回一個字符串在另一個字符串中第一次出現的位置。
- strrchr(): 它用於在另一個字符串中查找最後一次出現的字符串。
- strrev():用於反轉字符串。
參考:
http://php.net/manual/en/function.strripos.php
相關用法
- PHP strrchr用法及代碼示例
- PHP strrev()用法及代碼示例
- PHP strrchr()用法及代碼示例
- PHP strrpos() and strripos()用法及代碼示例
- PHP string rtrim()用法及代碼示例
- PHP strsrt()用法及代碼示例
- PHP strnatcasecmp()用法及代碼示例
- PHP string printf()用法及代碼示例
- PHP string ord()用法及代碼示例
- PHP string join()用法及代碼示例
- PHP strtolower()用法及代碼示例
- PHP str_split()用法及代碼示例
- PHP stream_get_filters()用法及代碼示例
- PHP strchr()用法及代碼示例
- PHP string sha1()用法及代碼示例
- PHP strcmp()用法及代碼示例
- PHP string setlocale()用法及代碼示例
- PHP string sha1_file()用法及代碼示例
- PHP string md5()用法及代碼示例
- PHP strptime()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP strripos() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。