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() は、 needlehaystack の中で最初に現れる位置を返します。 mb_strpos() とは異なり、 mb_stripos() は大文字小文字を区別しません。 needle が見つからなかった場合は false を返します。

パラメータ

haystack

needle が最初に現れる位置を見つける文字列。

needle

haystack の中で探す文字列。

offset

haystack の中で、検索を開始する位置。 負のオフセットは、文字列の末尾からのオフセットと解釈されます。

encoding

encoding パラメータには文字エンコーディングを指定します。省略した場合、もしくは null の場合は、 内部文字エンコーディングを使用します。

戻り値

needlehaystack の中で最初に現れる位置を返します。needle が見つからない場合は false を返します。

エラー / 例外

  • offsethaystack の長さより大きい場合、 ValueError がスローされます。

変更履歴

バージョン 説明
8.0.0 needle は、空の文字列も受け入れるようになりました。
8.0.0 encoding は、nullable になりました。
7.1.0 負の offset をサポートするようになりました。

参考

  • stripos() - 大文字小文字を区別せずに文字列が最初に現れる位置を探す
  • strpos() - 文字列内の部分文字列が最初に現れる場所を見つける
  • mb_strpos() - 文字列の中に指定した文字列が最初に現れる位置を見つける

add a note

User Contributed Notes 1 note

up
2
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 $spaceIsHereprint ($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. ;DHave a nice day, coder.
To Top