PHP 8.3.4 Released!

mb_strpos

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strpos查找字符串在另一个字符串中首次出现的位置

说明

mb_strpos(
    string $haystack,
    string $needle,
    int $offset = 0,
    ?string $encoding = null
): int|false

查找 string 在一个 string 中首次出现的位置。

基于字符数执行一个多字节安全的 strpos() 操作。 第一个字符的位置是 0,第二个字符的位置是 1,以此类推。

参数

haystack

要被检查的 string

needle

haystack 中查找这个字符串。 和 strpos() 不同的是,数字的值不会被当做字符的顺序值。

offset

搜索位置的偏移。如果没有提供该参数,将会使用 0。负数的 offset 会从字符串尾部开始统计。

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

返回 stringhaystackneedle 首次出现位置的数值。 如果没有找到 needle,它将返回 false

更新日志

版本 说明
8.0.0 现在 needle 接受空字符串。
8.0.0 现在 encoding 可以为 null。
7.1.0 支持负数的 offset

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top