Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP String strrpos() function returns the index number of last occurrence of specified text in the given string. Unlike strripos function, it is a case-sensitive function.

Note: The strrpos() function is a case-sensitive function.

Syntax

strrpos(string, find, start)

Parameters

string Required. Specify the string to search.
find Required. Specify the string to find.
start Optional. Specify the index number from where the search need to start.

Return Value

Returns the index number of last occurrence of specified text in the given string.

Example:

In the below example, strrpos() function is used to find the index number of last occurrence of "be" in the given string called MyString.

<?php
$MyString = "To be, or not to be, that is the question.";

echo strrpos($MyString, "be")."\n";
?>

The output of the above code will be:

17

Example:

In the below example, last occurrence of "be" is searched after the specified strating position.

<?php
$MyString = "To be, or not to be, that is the question.";

echo strrpos($MyString, "be", 5)."\n";
?>

The output of the above code will be:

17

❮ PHP String functions

5