96 of 410 menu

The mb_stristr Function

The mb_stristr function searches for the first occurrence of a substring in a string case-insensitively and returns the part of the string from the beginning of the found occurrence to the end. The first parameter is the string to search in, the second is the substring to find, the third (optional) is a boolean value to return the part of the string before the occurrence, and the fourth (optional) is the encoding.

Syntax

mb_stristr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false

Example

Let's find a substring in a string case-insensitively:

<?php $res = mb_stristr('ABCDE', 'bc'); echo $res; ?>

Code execution result:

'BCDE'

Example

Using the $before_needle parameter to get the part of the string before the occurrence:

<?php $res = mb_stristr('ABCDE', 'bc', true); echo $res; ?>

Code execution result:

'A'

Example

Search with UTF-8 encoding specified:

<?php $res = mb_stristr('Привет мир', 'МИР', false, 'UTF-8'); echo $res; ?>

Code execution result:

'мир'

See Also

  • the mb_strstr function,
    which performs a case-sensitive substring search
  • the stristr function,
    which is similar to mb_stristr but for single-byte encodings
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline