mb_strripos()

mb_strripos() — Finds position of last occurrence of a string within another, case insensitive.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

mb_strripos() performs multi-byte safe strripos() operation based on number of characters. needle position is counted from the beginning of haystack. First character's position is 0. Second character position is 1. Unlike mb_strrpos(), mb_strripos() is case-insensitive.

Signature

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

Parameters

ParameterTypeWhat it takes
$haystackstringThe string from which to get the position of the last occurrence of needle.
$needlestringThe string to find in haystack.
$offsetintMay be specified to begin searching an arbitrary number of characters into the haystack. Negative values will stop searching at an arbitrary point prior to the end of the haystack.
$encoding?stringThe encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return value

Return the numeric position of the last occurrence of needle in the haystack string, or false if needle is not found.

Example

The PHP manual ships no example for mb_strripos(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.0.0needle now accepts an empty string.
8.0.0encoding is nullable now.
8.0.0Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned.

See also

strripos(), strrpos(), mb_strrpos()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page mb_strripos() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.