赵小黑 发表于 2017-3-26 14:31:35

php获取文件扩展名多种方法

  由于都是简单函数,直接代码:

<?php
function getExtensionName($filePath){
$num=strrpos($filePath,'.');
$len=strlen($filePath);
$extension=substr($filePath,$num+1,$len-$num);
// return $len;
return $extension;
}
function getExt($filePath){
$arr=pathinfo($filePath);
return strtolower($arr['extension']);
}
function getExtension($filePath){
$arr=explode('.',$filePath);
return array_pop($arr);
}
function getExten($filePath){
$arr=explode('.',$filePath);
$num=count($arr)-1;
return $arr[$num];
}
function getFileExt($file_name){
while($extension=strpos($file_name,'.')){
$file_name=substr($file_name,$extension+1);
}
return $file_name;
}
$filePath="http://www.0551fangchan.com/index.php";
echo getExtensionName($filePath);
echo '<br />';
echogetExt($filePath);
echo '<br />';
echo getExtension($filePath);
echo '<br />';
echo getExten($filePath);
echo '<br />';
echo getFileExt($filePath);
  输出都是:
  php
php
php
php
php
页: [1]
查看完整版本: php获取文件扩展名多种方法