函数名:grapheme_strrpos()
适用版本:PHP 5 >= 5.3.0, PHP 7
用法:grapheme_strrpos(string $haystack, string $needle, int $offset = 0): int|false
说明:grapheme_strrpos() 函数用于在字符串中查找最后一次出现指定字符或子字符串的位置。与 strrpos() 函数类似,但是 grapheme_strrpos() 函数会考虑多字节字符的情况。
参数:
返回值:
示例:
$string = "Hello, 你好!";
$needle = "好";
$position = grapheme_strrpos($string, $needle);
if ($position !== false) {
echo "最后一次出现 \"$needle\" 的位置是:$position";
} else {
echo "未找到 \"$needle\"";
}
// 输出:最后一次出现 "好" 的位置是:9
注意:grapheme_strrpos() 函数用于处理多字节字符,特别适用于 Unicode 字符串的处理。在使用该函数时,需要确保 PHP 安装了 mbstring 扩展。