Function name: mb_stristr()
Applicable version: PHP 4.0.6 and above
Usage: The mb_strstr() function is used to find a specified substring in a string and returns the part from the specified substring to the end of the string. This function is a multibyte character-safe version of the strristr() function.
Syntax: mb_strstr(string $haystack, string $needle, bool $before_needle = false, string $encoding = mb_internal_encoding()): string|false
parameter:
Return value:
Example:
$str = "Hello, World!"; $substring = "WORLD"; $result = mb_stristr($str, $substring); echo $result; // 输出:World! $result = mb_stristr($str, $substring, true); echo $result; // 输出:Hello, $result = mb_stristr($str, "abc"); var_dump($result); // 输出:bool(false)
In the example above, we use the mb_strstring() function to search for $substring
in the string $str
. In the first example, the function returns the part from the substring World
to the end of the string, i.e. World!
. In the second example, we set the third parameter to true, and the function returns the part before the substring World
, i.e. Hello,
. In the last example, we searched for a substring abc
that does not exist and the function returns false.