Possible Duplicate:
How to extract a file extension in PHP?
I found the following function to get the extension of a file in a tutorial, but I think it's a bit too long. So I thought there would be a way to shorten this.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) return "";
$l = strlen($str) - $i;
$ext = substr($str, $i+1, $l);
return $ext;
}
The $str
would be a filename.
Is there a way to shorten this function, without affecting stability and output?
I've done something like this:
function getExtension($str) {
$ext = pathinfo($str)['extension'];
return $ext;
}
But that didn't work for me, but probably I did something wrong.