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


The PHP String strrchr() function is used to return a string which starts from last occurrence of the specified text to the end of the given string.

Note: The strrchr() function is a binary-safe function.

Syntax

strrchr(string, search)

Parameters

string Required. Specify the string to search.
search Required. Specify the string to search for in the given string. If number is provided instead of string, then it searches for last occurrence of the character having ASCII value matching with the number.

Return Value

Returns a string which starts from last occurrence of the specified text to the end of the given string.

Example:

In the below example, strrchr() function is used to return the part the string called MyString using search string "be".

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

$NewString = strrchr($MyString, "be");
echo $NewString;
?>

The output of the above code will be:

be, or not to be, that is the question

❮ PHP String functions