一个取得文件扩展名的php函数
时间:2007-02-17 来源:PHP爱好者
<?
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
/*
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
GetFileType
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
用法:GetFiletype($filename)
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
*/
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
function GetFiletype($Filename) {
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
if (substr_count($Filename, ".") == 0) { // 检查文件名中是否有.号。
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return; // 返回空
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
} else if (substr($Filename, -1) == ".") { // 检查是否以.结尾,即无扩展名
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return; // 返回空
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
} else {
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$FileType = strrchr ($Filename, "."); // 从.号处切割
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$FileType = substr($FileType, 1); // 去除.号
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return $FileType; // 返回
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
}
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
}
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$Filename = "Testfilename.php4";
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$Filename = GetFileType($Filename);
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
echo $Filename; // 打印出php4
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
?>
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
/*
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
GetFileType
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
用法:GetFiletype($filename)
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
*/
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
function GetFiletype($Filename) {
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
if (substr_count($Filename, ".") == 0) { // 检查文件名中是否有.号。
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return; // 返回空
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
} else if (substr($Filename, -1) == ".") { // 检查是否以.结尾,即无扩展名
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return; // 返回空
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
} else {
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$FileType = strrchr ($Filename, "."); // 从.号处切割
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$FileType = substr($FileType, 1); // 去除.号
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
return $FileType; // 返回
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
}
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
}
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$Filename = "Testfilename.php4";
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
$Filename = GetFileType($Filename);
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
echo $Filename; // 打印出php4
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
?>
wwww.chin aitpower.comJgkmXhZpetmBtRV3Om6dfHxDn
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +