public function lastIndexOf($string, $search, $toIndex = null)
    {
        $string = (string)$string;

        $length = mb_strlen($string, 'UTF-8');
        if ($toIndex === null) {
            $toIndex = $length;
        }
        $toIndex = max(0, $toIndex);
        if ($search === '') {
            return min($length, $toIndex);
        }
        $string = mb_substr($string, 0, $toIndex, 'UTF-8');
        $index = mb_strrpos($string, $search, 0, 'UTF-8');
        if ($index === false) {
            return -1;
        }
        return (integer)$index;
    }
public function lastIndexOf($string, $search, $toIndex = null)
    {
        $string = (string)$string;

        $length = mb_strlen($string, 'UTF-8');
        if ($toIndex === null) {
            $toIndex = $length;
        }
        $toIndex = max(0, $toIndex);
        if ($search === '') {
            return min($length, $toIndex);
        }
        $string = mb_substr($string, 0, $toIndex, 'UTF-8');
        $index = mb_strrpos($string, $search, 0, 'UTF-8');
        if ($index === false) {
            return -1;
        }
        return (integer)$index;
    }
public function lastIndexOf ( $ string , $ search , $ toIndex = null ) { $ string = ( string ) $ string ; $ length = mb_strlen ( $ string , 'UTF-8' ) ; if ( $ toIndex === null ) { $ toIndex = $ length ; } $ toIndex = max ( 0 , $ toIndex ) ; if ( $ search === '' ) { return min ( $ length , $ toIndex ) ; } $ string = mb_substr ( $ string , 0 , $ toIndex , 'UTF-8' ) ; $ index = mb_strrpos ( $ string , $ search , 0 , 'UTF-8' ) ; if ( $ index === false ) { return - 1 ; } return ( integer ) $ index ; }
Find the last position of a substring in the given string

Example::

String.lastIndexOf("Developers Developers Developers!", "Developers") == 22

@param string $string The input string
@param string $search The substring to search for
@param integer $toIndex The position where the backwards search should start, defaults to the end
@return integer The last index of the substring (>=0) or -1 if the substring was not found
Find the last position of a substring in the given string