101 of 410 menu

The mb_strrpos Function

The mb_strrpos function finds the position of the last occurrence of a substring in a string. It works with multibyte encodings (UTF-8, etc.). Its 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_strrpos( string $haystack, string $needle, int $offset = 0, string $encoding ): int|false

Example

Let's find the position of the last occurrence of a substring in a string:

<?php $res = mb_strrpos('аабабв', 'б'); echo $res; ?>

Code execution result:

3

Example

Search with UTF-8 encoding specified:

<?php $res = mb_strrpos('日本語', '語', 0, 'UTF-8'); echo $res; ?>

Code execution result:

2

Example

When the substring is not found, the function returns false:

<?php $res = mb_strrpos('abcde', 'z'); var_dump($res); ?>

Code execution result:

false

See Also

  • the mb_strpos function,
    which finds the first occurrence of a substring
  • the strrpos function,
    which finds the last occurrence without considering encoding
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