网上查阅后,自己动手写的:可能没有考虑周全存在错误。
![](/upload/ad_content/xuanchuantu-23.jpg)
成都创新互联主营岚皋网站建设的网络公司,主营网站建设方案,
成都app软件开发公司,岚皋h5
小程序设计搭建,岚皋网站营销推广欢迎岚皋等地区企业咨询//$filepath="d:\phptest\phptext.txt.zip";
//$filepath="d:\phptest\phptext";
//方法一
function Extend_1($filename)
{
$extends=explode(".",$filename);
$pos=count($extends)-1; //获取最后一个数组的位置
$ext=end($extends);
return $ext;
// return $extends[$pos];
}
echo Extend_1($filepath); //返回zip
//方法二
function Extend_2($filename)
{
$lastpos=strrchr($filename,"."); //获取"."在filaname中的最后出现位置,并返回从该位置到最后的字符串
return $lastpos;
}
echo Extend_2($filepath); //返回.zip
//方法三
function Extend_3($filename)
{
$lastpos=strripos($filename,"."); //获取"."在filaname中的最后出现位置
$extend=substr($filename,$lastpos);
return $extend;
}
echo Extend_3($filepath);//返回.zip
//方法四
function Extend_4($filename)
{
$strrev=strrev($filename); //反转字符串
$firstindex=strpos($strrev,".");//获取"."在filaname中的第一次出现位置
$extend=substr($strrev,0,$firstindex+1);
return strrev($extend);
}
echo Extend_4($filepath); //返回.zip
//方法五
function Extend_5($filename)
{
$filainfo=pathinfo($filename);
return $filainfo['extension'];
}
// echo Extend_5($filepath); //返回zip
//方法六
function Extend_6($filename) //注:最好使用这个
{
$filainfo=pathinfo($filename,PATHINFO_EXTENSION);
return $filainfo;
}
echo Extend_6($filepath);//返回zip
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:php获取文件扩展名的几种方法-创新互联
新闻来源:
http://shouzuofang.com/article/coppps.html