mb_strripos() 函數是 PHP 內置的不區分大小寫的函數,用於查找一個字符串在另一個字符串中最後一次出現的位置。
用法:
mb_strripos($haystack, $needle, $offset = 0,encoding = null): int|false
Parameters: 該函數接受如下四個參數:
- $haystack:該參數定義了一個字符串,我們將在其中搜索$針參數字符串。
 - $needle: 這是一個字符串參數,在$幹草堆 字符串參數。
 - $偏移量:這是一個可選參數,說明從哪裏開始搜索字符串,如果它定義為負數,它將從 $haystack 的末尾開始。
 - $encoding: 這是一個可選參數,說明字符串的編碼,如果未定義此參數,它將使用內部編碼。
 
返回值:該函數返回 haystack 字符串中最後一次出現的數字位置,否則將返回“false”。
示例 1:下麵的代碼說明了使用mb_strripos()函數。
PHP
<?php 
    $string = 'Geeks for Geeks'; 
    $substring = 'for'; 
      
    $pos = mb_strripos($string, $substring); 
      
    if ($pos !== false) { 
        echo "The last occurrence of '{$substring}'
             is at position {$pos} in '{$string}'."; 
    }  
    else { 
        echo "The substring '{$substring}' 
              was not found in '{$string}'."; 
    }   
?>輸出:
The last occurrence of 'for' is at position 6 in 'Geeks for Geeks'.
示例 2:下麵的代碼說明了使用mb_strripos()函數。
PHP
<?php 
    $string = 'Programming is not easy if you 
               does not use GeeksforGeeks'; 
    $substring = 'you'; 
    $offset = 10; 
       
    $pos = mb_strripos($string, $substring, $offset); 
       
    if ($pos !== false) { 
        echo "The last occurrence of '{$substring}' is at  
            position {$pos} in '{$string}',  
            starting from offset {$offset}."; 
    } 
    else { 
        echo "The substring '{$substring}' was not found  
        in '{$string}' after offset {$offset}."; 
    }    
?>輸出:
The last occurrence of 'you' is at position 27 in 'Programming is not easy if you does not use GeeksforGeeks', starting from offset 10.
參考:https://www.php.net/manual/en/function.mb-strripos.php
相關用法
- PHP mb_strrichr()用法及代碼示例
 - 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_strripos() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
