The strrchr() function finds the position of the last occurrence of a string, and returns all characters from this position to the end of the string.
PHP strrchr() Function has the following syntax.
strrchr(string,char)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to search |
char | Required. | String to find. If this is a number, it will search for the character matching the ASCII value of that number |
PHP strrchr() Function returns all characters from the last occurence of a string, to the end of the main string, or FALSE if the character is not found.
Search a string for "world", and return all characters from this position to the end of the string:
<?php
echo strrchr("Hello world from java2s.com!","world");
?>
The code above generates the following result.
Search a string for the ASCII value of "o" and return all characters from this position to the end of the string:
<?php
echo strrchr("Hello world from java2s.com!",111);
?>
The code above generates the following result.