The strripos() function behaves identically in PHP 8.4 and PHP 8.5. There are no version-specific changes or deprecations for this function in either release. The last documented behavioral change was in PHP 8.2.0, regarding locale independent case folding.
Function
strripos() finds the numeric position of the last occurrence of a substring within a string, ignoring case .
Signature:
strripos(string $haystack, string $needle, int $offset = 0): int|false
Key Behavior:
- Case-Insensitive: Unlike strrpos(), it does not distinguish between uppercase and lowercase letters.
- Return Value: Returns the position as an integer (starting at 0), or false if the needle is not found.
- Strict Comparison: Always use === false to check for a failed search, as a valid position of 0 would loosely evaluate to false.
Example
Here is the canonical example from the PHP documentation showing how to use it safely.
<?php
$haystack = ababcd ;
$needle = aB ;$pos = strripos($haystack, $needle);
if ($pos === false) {
echo "Sorry, we did not find ($needle) in ($haystack)";
} else {
echo "Congratulations! ";
echo "We found the last ($needle) in ($haystack) at position ($pos)";
}
?>
Output:
Congratulations!
We found the last (aB) in (ababcd) at position (2)
The search for aB matches the ab at index 2 (the second occurrence), because the function looks for the last match and ignores case.