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

phpstrripos(string, substring, [offset]);

Example

Find the last occurrence of a substring in a string:

php<?php
  $res = strripos('aBcAbD', 'ab');
  echo $res;
?>

Execution result:

php3

Example

Try to find a non-existent substring:

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

Execution result:

phpfalse

Example

Using the offset parameter to search after a specific position:

php<?php
  $res = strripos('aBcAbDab', 'ab', 4);
  echo $res;
?>

Execution result:

php6

See Also

  • the strpos function,
    which finds the first occurrence of a substring case-sensitively
  • the strrpos function,
    which finds the last occurrence of a substring case-sensitively
  • the stripos function,
    which finds the first occurrence of a substring case-insensitively