97 of 410 menu

The mb_strpos Function

The mb_strpos function finds the position of the first occurrence of a substring in a string with support for multibyte encodings (e.g., UTF-8). The first parameter is the string to search in, the second is the substring to find, the third (optional) is the starting position for the search, and the fourth (optional) is the encoding.

Syntax

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

Example

Find the position of a substring in a string:

<?php $res = mb_strpos('abcde', 'b'); echo $res; ?>

Code execution result:

1

Example

Search with a specified starting position (starting from the 3rd character):

<?php $res = mb_strpos('abcabc', 'a', 2); echo $res; ?>

Code execution result:

3

Example

Search in a string with Cyrillic characters (UTF-8):

<?php $res = mb_strpos('абвгде', 'в', 0, 'UTF-8'); echo $res; ?>

Code execution result:

2

See Also

  • the strpos function,
    which finds the position of a substring without considering multibyte encodings
  • the mb_strlen function,
    which returns the length of a string considering multibyte 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