Home >Backend Development >PHP Tutorial >A function to get the file extension_PHP tutorial
A function to get the file extension
/*
GetFileType
Usage: GetFiletype($filename)
*/
function GetFiletype($Filename) {
if (substr_count($Filename, ".") == 0) { // Check whether there is a . number in the file name.
return; // Return empty
} else if (substr($Filename, -1) == ".") { // Check whether it ends with ., that is, no extension
return; // Return empty
} else {
$FileType = strrchr ($Filename, "."); // Cut from . $FileType = substr ($ Filetype, 1); // Remove. No.
Return $ Filetype; // Return
}
}
$ filename = "testfilename.php4";
$Filename = GetFileType($Filename);
echo $Filename;