Mega Code Archive

 
Categories / Php / File Directory
 

Function to get the filetype from a filename

<? /* GetFileType */ function GetFiletype($Filename) { if (substr_count($Filename, ".") == 0) { // Check if there is a dot return; // Return Nothing } else if (substr($Filename, -1) == ".") { // Check if the string ends with . return; // Return Nothing } else { $FileType = strrchr ($Filename, "."); // Split the string where the dot is $FileType = substr($FileType, 1); // Remove the dot return $FileType; // Return the filetype } } $Filename = "Testfilename.php4"; $Filename = GetFileType($Filename); echo $Filename; // This prints out php4 ?>