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.
Syntax:
strrchr($string, $key)
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.
Examples:
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 1:
<?php // Input string $string = "Hello|welcome|to|gfg"; // key to be searched $key = "|"; echo strrchr($string, $key); ?> |
Output:
|gfg
Program 2: When $key contains escape sequence.
<?php // Input string $string = "Hello\nwelcome\nto\ngfg"; // key to be searched $key = "\n"; echo strrchr($string, $key); ?> |
Output:
gfg
Program 3: When $key contains more than one character.
<?php // Input string $string = "Hello|welcome|to|gfg"; // key to be searched $key = "|welcome"; echo strrchr($string, $key); ?> |
Output:
|gfg
Reference:
http://php.net/manual/en/function.strrchr.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- p5.js | log() function
- PHP | min( ) Function
- D3.js | d3.lab() Function
- D3.js | d3.hcl() Function
- D3.js | d3.map.set() Function
- p5.js | sin() function
- p5.js | cos() function
- p5.js | tan() function
- PHP | max( ) Function
- p5.js | red() function
- PHP | pos() Function
- PHP | key() Function
- p5.js | value() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



