#Get File Extension
Detects the file extension from a given string. This function returns the text following the last dot of the file name, so more complicated file extensions such as .tar.gz are only returned as ".gz".
function file_ext($file) {
$last_dot = strrpos($file, '.');
if ($last_dot !== false) {
return strtolower(substr($file, $last_dot + 1));
}
return 'file';
}
echo file_ext('test.txt'); // "txt"
echo file_ext('PAGE.HTML'); // "html"
echo file_ext('config'); // "file"