【php简单获取文件扩展名的方法】教程文章相关的互联网学习教程文章

获取文件扩展名函数

使用方法:echo FileExtension("name.txt"); 得到 txtfunction FileExtension($fstr){ $retval = ; $pt = strrpos($fstr, "."); if ($pt) $retval = substr($fstr, $pt+1, strlen($fstr) - $pt); return ($retval);}

php获取文件扩展名的几种方法

php获取文件扩展名的几种方法,有需要的朋友可以参考下。方法1:function get_extension($file) { substr(strrchr($file, .), 1); } 方法2:function get_extension($file) { return substr($file, strrpos($file, .)+1); } 方法3:function get_extension($file) { return end(explode(., $file)); } 方法4:function get_extension($file) { $info = pathinfo($file); return $info[extension]; } 方法5:function get_extension...

php文件扩展名获取方法汇总

//取文件的扩展名//by http://bbs.it-home.org$file = "/home/jbxue/file_20130322.txt";for($i=1; $i $func = 'get_file_ext_' . $i;var_dump($func($file));}function get_file_ext_1($file) {return strtolower(trim(substr(strrchr($file, '.'), 1)));}function get_file_ext_2($file) {return strtolower(trim(pathinfo($file, PATHINFO_EXTENSION)));}function get_file_ext_3($file) {return strtolower(trim(substr($file,...

php获取文件扩展名的三个方法

//取得文件的扩展名//by bbs.it-home.org//方法1function get_ext_file_1($file_name){$retval = "";$pt = strrpos($file_name, ".");if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt);return ($retval);}//方法2function get_ext_file_2($file_name){$get_ext_file = pathinfo($file_name);$get_ext_file = strtolower($get_ext_file["extension"]);return $get_ext_file;}//方法3function get_ext_file_3(...

php取得文件扩展名的三种方法(改进版)

//取文件的扩展名//by http://bbs.it-home.org//method 1function get_file_ext_1($fileName){ $retval=""; $pt=strtpos($fileName,"."); if($pt){ $retval=substr($fileName,$pt+1,strlen($fileName)-$pt); } if($retval!==""){ return $retval; } return false; } //method twofunction get_file_ext_2($fileName){ $extend = pathinfo($fileName); ...

一个获取文件扩展名的php自定义函数

<?/*获取文件的扩展名用法:GetFiletype($filename)*/function GetFiletype($Filename) {if (substr_count($Filename, ".") == 0) { // 检查文件名中是否有.号。 return; // 返回空} else if (substr($Filename, -1) == ".") { // 检查是否以.结尾,即无扩展名 return; // 返回空} else { $FileType = strrchr ($Filename, "."); // 从.号处切割 $FileType = substr($FileType, 1); // 去除.号 return $FileType; // 返回...

php获取文件扩展名的5种方法

//获取文件扩展名$file = 'jbxue.com.php';//方法1$path_info = pathinfo($file);//print_r($path_info);//echo "";//echo $path_info['dirname'];//echo "";//echo $path_info['basename'];echo "";echo strtolower($path_info['extension']);//方法2echo "---------------------";$p = strrpos($file,'.'); //得到最后一个点的位置echo strtolower(substr($file,$p+1));//方法3echo "---------------------";$arr = explode('.',...

php获取文件扩展名的二种方法

本文介绍下,用于获取文件扩展名的一段php代码,在php中获取扩展名,使用pathinfo()方法比较方便。有需要的朋友参考下。在php中,可以很方便地从文件末尾取得文件的扩展名。 使用php函数pathinfo,可以做到这一点,在使用中注意文件的扩展名前的点号。 使用pathinfo()获取到的扩展名,是不包括点号的。 以下介绍二种获取文件扩展名的方法,分别如下。 方法1,方法二,与方法一基本相同,不过它使用字符串操作来得到扩展名,使用.号...

php怎么获取文件扩展名?php获得文件扩展名三种方法

php怎么获取文件扩展名,php获取文件扩展名的有哪些技巧,通过实例学习php取得文件扩展名的几种方法,例子比较简单,适合作为php入门教程参考。php怎么获取文件扩展名?有哪些方法? 一、php简单获取文件扩展名的例子:代码示例: 输出:jpg ?> 二、php获得文件扩展名三种方法 例子:代码示例: //方法二 function extend_2($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend["extension"]); r...

php获取url中文件扩展名

//取出url地址中文件扩展名$url = "http://sdk.tools.sinaapp.com/index.php?appname=beipiao&version=1";function getFileName($url){$a = explode(?, $url);$b = strrpos($a[0], .); //strrpos(被搜索字符串,要查找字符串,[查找开始的位置]) 查找字符串最后一次出现的位置: 找到则返回最后一次出现的位置;未找到则返回false$c = substr($a[0], $b+1, 3); //substr(被操作字符串,开始位置,[结束位置]) 返回字符串的一部...

一个取得文件扩展名的函数_PHP教程

一个取得文件扩展名的函数 /* GetFileType 用法:GetFiletype($filename) */ function GetFiletype($Filename) { if (substr_count($Filename, ".") == 0) { // 检查文件名中是否有.号。 return; // 返回空 } else if (substr($Filename, -1) == ".") { // 检查是否以.结尾,即无扩展名 return; // 返回空 } else { $FileType = strrchr ...

php获得文件扩展名三法_PHP教程

代码如下://方法一: function extend_1($file_name) { $retval=""; $pt=strrpos($file_name, "."); if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt); return ($retval); } //方法二 function extend_2($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend["extension"]); return $extend; } //方法三 function extend_3($file_name) { $extend =explode("." , ...

PHP文件扩展名获取函数_PHP教程

代码如下:$file = "/home/lvyaozu/backup_20080115.txt"; for($i=1; $i $func = 'get_file_ext_' . $i; var_dump($func($file)); } function get_file_ext_1($file) { return strtolower(trim(substr(strrchr($file, '.'), 1))); } function get_file_ext_2($file) { return strtolower(trim(pathinfo($file, PATHINFO_EXTENSION))); } function get_file_ext_3($file) { return strtolower(trim(substr($file, strrpos($file, '.'...

PHP中获取文件扩展名的N种方法小结_PHP教程

第1种方法: 代码如下:function get_extension($file) { substr(strrchr($file, .), 1); } 第2种方法: 代码如下:function get_extension($file) { return substr($file, strrpos($file, .)+1); } 第3种方法: 代码如下:function get_extension($file) { return end(explode(., $file)); } 第4种方法: 代码如下:function get_extension($file) { $info = pathinfo($file); return $info[extension]; } 第5种方法: 代码如...

编程小技巧PHP获文件扩展名的三种方法_PHP教程

方法一:function extend_1($file_name) { $retval=""; $pt=strrpos($file_name, "."); if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt); return ($retval); } ?> 方法二:function extend_2($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend["extension"]); return $extend; } 方法三:function extend_3($file_name) { $extend =explode("." , $file_name); $va=count($exte...