The strripos Function
The strripos
function finds the position of the last occurrence of a substring in a string, ignoring case.
If the substring is not found, the function returns false
. The first parameter is the string to search in,
the second is the substring to find, and the third optional parameter can specify the position to start the search from.
Syntax
strripos(string, substring, [offset]);
Example
Find the last occurrence of a substring in a string:
<?php
$res = strripos('aBcAbD', 'ab');
echo $res;
?>
Execution result:
3
Example
Try to find a non-existent substring:
<?php
$res = strripos('abcde', 'z');
var_dump($res);
?>
Execution result:
false
Example
Using the offset parameter to search after a specific position:
<?php
$res = strripos('aBcAbDab', 'ab', 4);
echo $res;
?>
Execution result:
6