99 of 410 menu

The mb_strrichr Function

The mb_strrichr function performs a case-insensitive search for the last occurrence of a substring in a string. Unlike strrchr, it works with multibyte encodings (UTF-8, etc.). Returns the part of the string from the last found occurrence to the end of the string or false if the substring is not found.

Syntax

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

Example

Find the last occurrence of a substring in a string case-insensitively:

<?php $res = mb_strrichr('aBcAbC', 'ab'); var_dump($res); ?>

Code execution result:

'AbC'

Example

Find the part of the string before the found occurrence:

<?php $res = mb_strrichr('aBcAbC', 'ab', true); var_dump($res); ?>

Code execution result:

'aBc'

Example

Example with UTF-8 encoding specified:

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

Code execution result:

'Мир'

See Also

  • the mb_strrchr function,
    which searches for the last occurrence of a substring case-sensitively
  • the mb_stripos function,
    which searches for the position of the first occurrence of a substring case-insensitively
  • the mb_strstr function,
    which searches for the first occurrence of a substring case-sensitively
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