PHP | strrchr Function
The strrchr() function is a built-in function in PHP. This function takes two arguments a string and a character. This function searches the given character in the given string and returns the portion of string starting from the last occurrence of the given character in that string.
Parameters: This function accepts two parameters. Both of the parameters are mandatory and are described below:
- $string: This is the input string in which we want to search the given key.
- $key: This parameter represents a character to be searched in the given string $string. If this parameter contains more than one character then only the first character of this parameter will be searched in $string.
Return Value: This function returns the portion of $string starting from the last occurrence of the given $key in that string.
Input : $string = "Hello|welcome|to|gfg" $key = '|' Output : |gfg Input : $string = "Welcome\nto\ngfg" $key = '\n' Output : gfg
Below programs illustrate the strrchr() function in PHP:
Program 2: When $key contains escape sequence.
Program 3: When $key contains more than one character.