Home  >  Article  >  Backend Development  >  A php function to get the file extension_PHP tutorial

A php function to get the file extension_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:30:36798browse


/*
GetFileType
Usage: GetFiletype($filename)
*/

function GetFiletype($Filename) {

if (substr_count($Filename, ".") == 0) { // Check whether there is a . sign 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 . number
$FileType = substr ($FileType, 1); // Remove . number
return $FileType; // Return
}
}


$Filename = "Testfilename.php4";

$Filename = GetFileType($Filename);

echo $Filename; // Print out php4

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509170.htmlTechArticle/* GetFileType usage: GetFiletype($filename) */ function GetFiletype($Filename) { if (substr_count($ Filename, ".") == 0) { // Check whether there is a . sign in the file name. return; // Return empty...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn