ฟังก์ชัน mb_strrpos() ใน PHP ใช้หาตำแหน่ง last occurrence ของ string ในอีก string หนึ่ง ฟังก์ชันนี้ทำ multibyte safe strrpos() operation ตามจำนวน characters นับตำแหน่ง needle จากต้น haystack string
Syntax
int mb_strrpos( $str_haystack, $str_needle, $int_offset=0, $str_encoding=empty )
Parameters
mb_strrpos() รับ 4 พารามิเตอร์:
$str_haystack – string ตรวจสอบ last existence ของ needle
$str_needle – needle string ที่จะหาใน haystack
$int_offset – ค้นหา arbitrary number ของ characters ใน string หาก negative จะหยุดค้นหาที่ arbitrary point จนจบ string
$str_encoding – character encoding parameter หาก omit จะใช้ internal character encoding
Return Values
mb_strrpos() คืนค่าตำแหน่ง numeric ของ last occurrence ของ needle ใน haystack คืนค่า False หากไม่เจอ needle
Example 1
<?php
// Encoding UTF-8
mb_internal_encoding("UTF-8");
// Used hello world string
$integer = mb_strrpos ("Hello World", "ol", 0);
// Output
var_dump($integer);
?>
Output
bool(false)
Note – โค้ด PHP ข้างต้นคืนค่า False เพราะ needle string ไม่ match กับ haystack string ที่ให้
Example 2
<?php
// Encoding UTF-8
mb_internal_encoding("UTF-8");
// Used hello world string
$integer = mb_strrpos ("Hello World", "He");
// output
var_dump($integer);
?>
Output
int(0)