PHP 內置函數中的 strrchr() 函數。它用於查找字符串最後一次出現的位置。
此函數返回從該位置到字符串末尾的所有字符,如果未找到該字符,則返回 FALSE。
注意:strrchr() 函數是二進製安全的。
用法:
strrchr(string,char);
參數 | 描述 | 必需/可選 |
---|---|---|
String | 指定要搜索的字符串。 | required |
Char | 使用 ASCII 值指定要查找的字符串。 | required |
例子1
<?php
$str1="Hello PHP";
$str2="PHP";
echo "Your first string is:".$str1;
echo "<br>";
echo "Your second string is:".$str2;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr($str1,$str2);
?>
輸出:
Your first string is:Hello PHP Your second string is:PHP By using 'strrchr()' function:P
例子2
<?php
$str="We are Learning PHP";
echo "Your string is:".$str;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr("$str",are);
?>
輸出:
Your string is:We are Learning PHP By using 'strrchr()' function:arning PH
例子3
<?php
$str="Hello PHP";
echo "Your string is:".$str;
echo "<br>";
echo "By using 'strrchr()' function:".strrchr("$str",101);
// Search a string for the ASCII value of "e" (101) and
//return all characters from this position to the end of the string:
?>
輸出:
Your string is:Hello PHP By using 'strrchr()' function:ello PHP
另見:
strncmp():前n個字符的字符串比較(區分大小寫)
strpbrk():在字符串中搜索任何一組字符
strpos():返回一個字符串在另一個字符串中第一次出現的位置(區分大小寫)
參考資料:
http://php.net/manual/en/function.strrchr.php相關用法
- PHP strrchr用法及代碼示例
- PHP strrev()用法及代碼示例
- PHP strripos()用法及代碼示例
- 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 strrchr() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。