Home >Backend Development >PHP Problem >How to use php strrchr function?
php The strrchr function is used to find the last occurrence of a string in another string and return all characters from that position to the end of the string. Its syntax is strrchr(string,char).
php How to use strrchr function?
Definition and Usage
strrchr() function finds the last occurrence of a string in another string and returns the character from that position to All characters at the end of the string.
Note: This function is binary safe.
Syntax
strrchr(string,char)
Parameters
string Required. Specifies the string to search for.
char required. Specifies the characters to search for. If the argument is a number, searches for characters matching the ASCII value of this number.
Return value:
Returns all characters from the last occurrence of a string in another string to the end of the main string.
If this character is not found, returns FALSE.
PHP Version: 4
Change Log: In PHP 4.3, this function became binary safe.
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); ?>
Output:
What a beautiful day!
Example 2
Search for the position of "o" in the string using the ASCII value of "o" and return the position from that position to the string All characters ending with:
<?php echo strrchr("Hello world!",101); ?>
Output:
ello world!
Example 3
Search for the position of "Shanghai" in the string and return the position from that All characters up to the end of the string:
<?php echo strrchr("I love Shanghai!","Shanghai"); ?>
Output:
Shanghai!
The above is the detailed content of How to use php strrchr function?. For more information, please follow other related articles on the PHP Chinese website!