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

A function to get the file extension_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:02:40908browse

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;


http://www.bkjia.com/PHPjc/316537.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316537.htmlTechArticleA function to get the file extension? /* GetFileType usage: GetFiletype($filename) */ function GetFiletype($ Filename) { if (substr_count($Filename, .) == 0) {// Check whether the file name is...
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