I have made a function that so far seems to be really good at getting the file extension no matter how strange the file name is. Every method I have come across on the net seems to like using explode on the . to get the extension, but what if the file name has multiple .s in it?
Here is my function:
$fileName = 'my.reallyAwk-ward..file--name.JPEG' ;
echo getExtension($fileName) ;
function getExtension($fileName)
{
$ext = explode('.', strrev($fileName), 2) ;
$ext = strtolower(strrev($ext[0])) ;
return $ext ;
}
Am I reinventing a wheel or can this be made more efficient?
From http://php.net/manual/en/function.pathinfo.php