mb_strrchr
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
mb_strrchr — 查找指定字符在另一个字符串中最后一次的出现
说明
mb_strrchr(
string
string
bool
?string
): string|false
string
$haystack
,string
$needle
,bool
$before_needle
= false
,?string
$encoding
= null
): string|false
mb_strrchr() 查找了 needle
在 haystack
中最后一次出现的位置,并返回 haystack
的部分。
如果没有找到 needle
,它将返回 false
。
参数
返回值
返回 haystack
的一部分。
或者在没有找到 needle
时返回 false
。
更新日志
版本 | 说明 |
---|---|
8.0.0 |
现在 needle 接受空字符串。
|
8.0.0 |
现在 encoding 可以为 null。
|
参见
- strrchr() - 查找指定字符在字符串中的最后一次出现
- mb_strstr() - 查找字符串在另一个字符串里的首次出现
- mb_strrichr() - 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现
+添加备注
用户贡献的备注 1 note
Anonymous ¶
1 year ago
needle: /
string: o/a/i
if before_needle is 1 then needle is excluded: "o/a"
if before_needle is false then needle is included: "/i"
as code:
$str="o/a/i";
$cs="/";
echo "if before_needle == 1 then needle is excluded"."\n";
$str="o/a/i";
$cs="/";
echo mb_strrchr ($str,$cs,1)."\n";
echo "if before_needle == false then needle is included"."\n";
$str="o/a/i";
$cs="/";
echo mb_strrchr ($str,$cs,0)."\n";