THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP strrchr() Function

❮ PHP String Reference

Example

Search a string for "world", and return all characters from this position to the end of the string:

<?php
echo strrchr("Hello world!","world");
?>
Run example »

Definition and Usage

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

Note: This function is binary-safe.


Syntax

strrchr(string,char)

Parameter Description
string Required. Specifies the string to search
char Required. Specifies the string to find. If this is a number, it will search for the character matching the ASCII value of that number

Technical Details

Return Value: Returns all characters from the last occurrence of a string within another string, to the end of the main string, or FALSE if the character is not found
PHP Version: 4+
Changelog: This function was made binary-safe in PHP 4.3

More Examples

Example 1

Search a string for "What", and return all characters from this position to the end of the string:

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

Example 2

Search a string for the ASCII value of "e" (101) and return all characters from this position to the end of the string:

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

❮ PHP String Reference