ฟังก์ชัน mb_stristr() ใน PHP ใช้ค้นหา first existence ของ string ในอีก string หนึ่ง ฟังก์ชันนี้ ไม่ case-sensitive mb_stristr() ค้นหา first existence ของ needle ใน haystack ที่กำหนด และคืนค่าส่วนของ haystack คืนค่า False หากไม่เจอ needle
Syntax
string mb_stristr( $str_haystack, $str_needle, $bool_before_needle=false, $str_encoding=empty )
Parameters
mb_stristr() รับ 4 พารามิเตอร์:
$str_haystack – string ใช้หา first existence ของ needle
$str_needle – string ที่จะหาใน haystack
$bool_before_needle – 决定 ส่วนของ haystack ที่จะคืนค่า
ถ้า True คืนค่า haystack ทั้งหมดตั้งแต่ต้นจนถึง first existence ของ needle (exclude needle)
ถ้า False คืนค่า haystack ทั้งหมดตั้งแต่ first existence ของ needle จนจบ (include needle)
$str_encoding – คืนค่าตำแหน่ง haystack หรือ False หากไม่เจอ
Return Values
mb_stristr() คืนค่าส่วนของ haystack string หากเจอ needle คืนค่า False หากไม่เจอ
Example 1
<?php
// using string Hello World
// using false needle
$string = mb_stristr("Hello World","or", false);
// output
print_r($string);
?>
Output
orld
Example 2
<?php
// using string Hello World
// using true needle
$string = mb_stristr("Hello World","or", true);
// output
print_r($string);
?>
Output
Hello W
Note – mb_stristr() ทำงานเหมือน strichr() แตต่างกันที่ mb_stristr() เป็น case-insensitive