Hàm mb_strripos() tìm vị trí xuất hiện cuối cùng của chuỗi con (needle) trong chuỗi (haystack). Không phân biệt chữ hoa/thường (case-insensitive). Dựa trên số ký tự (character), không phải byte. Trả về vị trí tính từ đầu haystack (0-index).
Cú pháp
int|false mb_strripos(
string $haystack,
string $needle,
int $offset = 0,
string $encoding = null
)
Tham số
| Tham số | Mô tả |
|---|---|
$haystack |
Chuỗi được tìm kiếm trong đó. |
$needle |
Chuỗi con cần tìm. |
$offset |
Vị trí bắt đầu tìm (tính từ đầu). Nếu âm: tính từ cuối. |
$encoding |
Encoding ký tự. Null = internal encoding. |
Giá trị trả về
Vị trí số (int) của lần xuất hiện cuối cùng của needle. false nếu không tìm thấy.
Ví dụ
<?php
mb_internal_encoding("UTF-8");
// Tìm "Wo" trong "Hello World" (case-insensitive)
$pos = mb_strripos("Hello World", "Wo", 0, "UTF-8");
var_dump($pos); // int(6)
// So sánh với mb_strrpos (case-sensitive)
$pos2 = mb_strrpos("Hello World", "wo", 0, "UTF-8");
var_dump($pos2); // bool(false) - không tìm thấy do case-sensitive
?>
Kết quả
int(6)
bool(false)
Hàm liên quan
mb_strrpos()– Case-sensitive version.mb_stripos()– Tìm lần đầu (case-insensitive).mb_strpos()– Tìm lần đầu (case-sensitive).strripos()– Phiên bản non-multibyte (single-byte encoding).