PHP strrchr() Function

Example

Search for the position of 'Shanghai' in the string and return all characters from that position to the end of the string:

<?php
echo strrchr("I love Shanghai!","Shanghai");
?>

Run Instances

Definition and Usage

The strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.

Note:This function is binary safe.

Syntax

strrchr(string,char)
Parameters Description
string Required. Specifies the string to be searched.
char Required. Specifies the character to be searched. If this parameter is a number, it searches for a character that matches the ASCII value of this number.

Technical Details

Return Value:

Returns all characters from the last occurrence of a string in another string to the end of the main string.

If the character is not found, FALSE is returned.

PHP Version: 4+
Update Log: In PHP 4.3, this function became binary safe.

More Examples

Example 1

Search for the position of 'What' in the string and return all characters from that position to the end of the string:

<?php
echo strrchr("Hello world! What a beautiful day!",What);
?>

Run Instances

Example 2

Search for the position of 'o' based on its ASCII value in the string and return all characters from that position to the end of the string:

<?php
echo strrchr("Hello world!",101);
?>

Run Instances