mb_strrpos
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_strrpos — 查找字符串在一个字符串中最后出现的位置
说明
基于字符数执行一个多字节安全的 strrpos() 操作。
needle
的位置是从 haystack
的开始进行统计的。
第一个字符的位置是 0,第二个字符的位置是 1。
参数
更新日志
版本 | 说明 |
---|---|
8.0.0 |
现在 needle 接受空字符串。
|
8.0.0 |
已经删除将 encoding 作为第三个参数而不是偏移量传递。
|
8.0.0 |
现在 encoding 可以为 null。
|
参见
- mb_strpos() - 查找字符串在另一个字符串中首次出现的位置
- mb_internal_encoding() - 设置/获取内部字符编码
- strrpos() - 计算指定字符串在目标字符串中最后一次出现的位置
+添加备注
用户贡献的备注 2 notes
Anonymous ¶
19 years ago
mb_strrpos throws a warning if $haystack is empty.
strrpos simply returns FALSE.
This is something to be wary of if overloading the mb functions.
Anonymous ¶
9 years ago
"Negative values will stop searching at an arbitrary point prior to the end of the string. " ist misleading.
The needle may not fully part of searchrange, defined by a negative offset.
A negative offsets marks the last byte, where a search could start.
<?php
$test = "Hallo, Herr Gött";
var_dump(strlen($test)); // int(17)
var_dump(mb_strrpos($test,'ött',13)); // int(13)
var_dump(mb_strrpos($test,'ött',-4)); // int(13) 17-4 = 13
var_dump(mb_strrpos($test,'ött',-5)); // bool(false)
?>