strrchr
strrchr
Find the last occurrence of a character in a string
**strrchr** string $haystack string $needle bool $before_needle
This function returns the portion of which
starts at the last occurrence of and goes
until the end of .
haystack``needle``haystack
haystackThe string to search in
needle
If contains more than one character,
only the first is used. This behavior is different from that of
.
needle``strstr
before_needle
If true,
returns the part of the before the
last occurrence of the (excluding the needle).
strrchr``haystack``needle
This function returns the portion of string, or false if
is not found.
needle
Voorbeeld: example
<?php
$ext = strrchr('somefile.txt', '.');
echo "file extension: $ext \n";
$ext = $ext ? strtolower(substr($ext, 1)) : '';
echo "file extension: $ext";
?>
file extension: .txt
file extension: txt
strstr``strrpos