mb_strrchr
Find the last occurrence of a specified character in another string
Function name: mb_strrchr()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Usage: mb_strrchr(string $haystack, string $needle [, bool $part = false [, string $encoding = mb_internal_encoding()]]): string|false
Description: The mb_strrchr() function looks for the last occurrence of the needle in the specified string haystack and returns the string and all the characters after it. Unlike the standard strrchr() function, the mb_strrchr() function can handle multibyte characters.
parameter:
Return value: Returns the found string, if not found, returns false.
Example:
// 示例1:查找最后一次出现的字符$str = "Hello World"; $lastPos = mb_strrchr($str, "o"); echo $lastPos; // 输出"orld" // 示例2:查找最后一次出现的字符串$str = "Hello World"; $lastPos = mb_strrchr($str, "lo"); echo $lastPos; // 输出"lo World" // 示例3:返回needle 及其后面的所有字符$str = "Hello World"; $lastPos = mb_strrchr($str, "o", true); echo $lastPos; // 输出"o World"
Notes: