mb_strstr
Find the first occurrence of a string in another string
Function name: mb_strstr()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Usage: mb_strstr(string $haystack, string $needle, bool $before_needle = false, string $encoding = null): string|false
Description: The mb_strstr() function is used to find the substring $needle in the string $haystack and return part of the string after $needle. This function is similar to the native strstr() function, but supports multibyte character sets.
parameter:
Return value:
Example:
$str = "Hello, World!"; $needle = "World"; // 在$str 中查找$needle 并返回$needle 后的部分字符串$result = mb_strstr($str, $needle); echo $result; // 输出: World! // 在$str 中查找$needle 并返回$needle 之前的部分字符串$result = mb_strstr($str, $needle, true); echo $result; // 输出: Hello, // 使用指定的字符编码进行查找$str = "你好,世界!"; $needle = "世界"; $result = mb_strstr($str, $needle, false, 'UTF-8'); echo $result; // 输出: 世界!
Notes: