betterCode() PHP 2025

mb_stripos

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

mb_stripos大小写不敏感地查找字符串在另一个字符串中首次出现的位置

说明

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

mb_stripos() 返回 needle 在字符串 haystack 中首次出现位置的数值。 和 mb_strpos() 不同的是,mb_stripos() 是大小写不敏感的。 如果 needle 没找到,它将返回 false

参数

haystack

在这个字符串中查找获取 needle 首次出现的位置

needle

haystack 中查找这个字符串

offset

haystack 里开始搜索的位置。如果是负数,就从字符串的尾部开始统计。

encoding

使用的字符编码名称。 如果省略了它,将使用内部字符编码。

返回值

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

错误/异常

  • 如果 offset 大于 haystack 的长度,则会抛出 ValueError 异常。

更新日志

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

参见

  • stripos() - 查找字符串首次出现的位置(不区分大小写)
  • strpos() - 查找字符串首次出现的位置
  • mb_strpos() - 查找字符串在另一个字符串中首次出现的位置

添加备注

用户贡献的备注 1 note

up
1
FangTS_
6 years ago
How works on examples mb_stripos:

First we will watch example on symbols(..?).
<?php
$text
= "Look! It's a text! Wow!"; //simple text
$spaceIsHere = mb_stripos($text," "); //you can replace " " on something what you need or want
$text2 = mb_substr($text,$spaceIsHere); //cutting text with $spaceIsHere
print ($text2);
/* Print will show that result:
" It's a text! Wow!"
Look. That " " wasn't cutted, because mb_substr don't write in var position after " " - he write WHERE is " " in string. */
?>

Also it can work on words, sentences...
Here's one of examples:
<?php
$text
= "Look! It's a text! Wow!"; //familiar text, right?)
$afterNeededWord = mb_stripos($text,"text!"); //you can replace "text!" on something else what you need
$text3 = mb_substr($text, $afterNeededWord); //cutting string (it is string? im stupid in that question xD)
print ($text3);
/* Print will show that result:
"text! Wow!"
Explaining the same. */
?>

I hope it was useful with my "good" English skills. ;D
Have a nice day, coder.
To Top