The strrchr Function
The strrchr
function finds the last
occurrence of a character in a string and returns the part
of the string starting from that point to the end.
If the second parameter consists of more than
one character, only the first character is used.
Syntax
strrchr(string $haystack, string $needle): string|false
Example
In this example, the function will extract the page address
from the URL (returns a substring starting from the last
/
to the end of the string):
<?php
echo strrchr('site.ru/dir1/dir2/page.html', '/');
?>
Code execution result:
'/page.html'
See Also
-
the
strchr
function,
which finds the first occurrence of a character and returns the remainder