100 of 410 menu

The mb_strripos Function

The mb_strripos function finds the position of the last occurrence of a substring in a string, ignoring character case. The first parameter is the string to search in, the second is the substring to search for. The third optional parameter specifies the position to start the search from. The fourth optional parameter specifies the encoding.

Syntax

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

Example

Find the last occurrence of a substring in a string:

<?php $res = mb_strripos('aBcDeBc', 'bc'); echo $res; ?>

Execution result:

5

Example

Search with a specified starting position:

<?php $res = mb_strripos('aBcDeBc', 'bc', 3); echo $res; ?>

Execution result:

5

Example

If the substring is not found, the function will return false:

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

Execution result:

false

See Also

  • the mb_strpos function,
    which finds the first occurrence of a substring case-sensitively
  • the strripos function,
    which finds the last occurrence of a substring ignoring case
byenru