mb_strrichr()function 是不區分大小寫的內置函數。此函數在多字節字符串中搜索最後一次出現的指定字符並返回該字符串的部分。
用法:
mb_strrichr( $haystack, $needle, $before_needle , $encoding) : string|false
參數:該函數接受 4 個參數,如下所述。
- $幹草堆:該參數指定從字符串中檢索最後一次出現的needle。
 - $needle:字符或字符串搜索$幹草堆.
 - $before_needle:如果“true”,該函數返回前麵的字符串部分$針而不是其後麵的部分。默認為“false”。
 - $編碼:這是一個可選參數,帶有字符串的字符編碼。如果未提供,則使用內部編碼。
 
返回值:這mb_strrichr()函數返回最後一次出現的指定字符或子字符串之後或之前的字符串部分,具體取決於$before_needle範圍。如果未找到該字符或子字符串,該函數將返回“false”。
示例 1:下麵的程序演示了mb_strrichr()函數。
PHP
<?php 
$str = "Hello, world!"; 
$needle = ","; 
$portion = mb_strrichr($str, $needle); 
echo $portion; 
?>輸出
, world!
示例 2:下麵的程序演示了mb_strrichr()函數。
PHP
<?php 
$haystack = "Hello, world!"; 
$needle = "o"; 
  
$lastOccurrence = mb_strrichr($haystack, $needle); 
  
if ($lastOccurrence !== false) { 
    echo 
 "The last occurrence of '$needle' in the haystack is: $lastOccurrence"; 
} else { 
    echo "The needle '$needle' was not found in the haystack."; 
} 
?>輸出
The last occurrence of 'o' in the haystack is: orld!
參考: https://www.php.net/manual/en/function.mb-strrichr.php
相關用法
- PHP mb_strripos()用法及代碼示例
 - PHP mb_strrchr()用法及代碼示例
 - PHP mb_strlen()用法及代碼示例
 - PHP mb_strtolower()用法及代碼示例
 - PHP mb_strtoupper()用法及代碼示例
 - PHP mb_str_split()用法及代碼示例
 - PHP mb_strimwidth()用法及代碼示例
 - PHP mb_stristr()用法及代碼示例
 - PHP mb_strstr()用法及代碼示例
 - PHP mb_strpos()用法及代碼示例
 - PHP mb_stripos()用法及代碼示例
 - PHP mb_strcut()用法及代碼示例
 - PHP mb_substr_count()用法及代碼示例
 - PHP mb_substr()用法及代碼示例
 - PHP mb_substitute_character()用法及代碼示例
 - PHP mb_split()用法及代碼示例
 - PHP mb_scrub()用法及代碼示例
 - PHP mb_convert_case()用法及代碼示例
 - PHP mb_check_encoding()用法及代碼示例
 - PHP mb_chr()用法及代碼示例
 - PHP mb_detect_order()用法及代碼示例
 - PHP mb_ereg()用法及代碼示例
 - PHP mb_http_input()用法及代碼示例
 - PHP mb_convert_encoding()用法及代碼示例
 - PHP mb_parse_str()用法及代碼示例
 
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP mb_strrichr() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
