PHP获取文件扩展名

1.

substr(strrchr("http://www.xxx.com/public/abc.jpg", ‘.‘), 1);

string strrchr(‘string‘,‘needle‘) 获取字符串中出现指定字符串的最后位置到末尾的内容
int strrpos(‘string‘,‘needle‘) 获取字符串中出现指定字符串的最后位置
string substr(‘string‘,‘position‘) 从指定位置截取字符串到末尾
string strchr(‘string‘,‘needle‘) 获取字符串中出现指定字符串的最先位置到末尾的内容
int strpos(‘string‘,‘needle‘) 获取字符串中出现指定字符串的最先位置

2.

substr($path, strrpos($path, ‘.‘) + 1)

3.

array_pop(explode(‘.‘, $path))

4.

(pathinfo($path))[‘extension‘]

  pathinfo($path) 返回: 

‘dirname‘ => string ‘http://www.baidu.com/public‘ (length=27)

‘basename‘ => string ‘abc.jpg‘ (length=7)

‘extension‘ => string ‘jpg‘ (length=3)

‘filename‘ => string ‘abc‘ (length=3)

原文地址:https://www.cnblogs.com/mzhaox/p/11218146.html

时间: 2024-07-31 22:21:52

PHP获取文件扩展名的相关文章

PHP中获取文件扩展名的N种方法

PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第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(expl

PHP获取文件扩展名五种以上的方法和注释

在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法还有一些注释: 一.方法 $file = ‘需要进行获取扩展名的文件.php’; 1. function getExt1($file) { return substr(strrchr($file,’.'),1); }2. function getExt2($file) { return substr($file,strrpos($file,’.')+1); }3. function getExt3($

获取文件扩展名

函数名称: strrchr 函数原型:char *strrchr(const char *str, char c); 所属库: string.h 函数功能:查找一个字符c在另一个字符串str中末次出现的位置(也就是从str的右侧开始查找字符c首次出现的位置),并返回从字符串中的这个位置起,一直到字符串结束的所有字符.如果未能找到指定字符,那么函数将返回NULL. 相关函数功能: 获取文件扩展名 宽字符获取文件扩展名:wcsrchr

PHP中 获取文件扩展名的N种方法

PHP中获取文件扩展名的N种方法,有以下这几种方式:第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种

python获取文件扩展名的方法(转)

主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path):   return os.path.splitext(path)[1] print file_extension('C:\py\wxPython.gif') 输出结果为:.gif 原文地址:https://www.cnblogs.com/hixiaowei/p/8438930.html

python获取文件扩展名的方法

主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): return os.path.splitext(path)[1] print file_extension('C:\py\wxPython.gif') 输出结果为:.gif 原文地址:https://www.cnblogs.com/sea-stream/p/10231908.html

PHP获取文件扩展名的五种方式

这是我应聘实习时遇到的一道笔试题: 使用五种以上方式获取一个文件的扩展名. 要求:dir/upload.image.jpg,找出 .jpg 或者 jpg , 必须使用PHP自带的处理函数进行处理,方法不能明显重复,可以封装成函数,比如 get_ext1($file_name), get_ext2($file_name) 下面是我参考网上资料总结出来的五种方法,都比较简单,话不多说,直接上代码: 方法1: function getExt1($filename) { $arr = explode('

使用五种方法获取文件扩展名

方法一: function get_ext1($path) { return strrchr($path,'.'); } echo get_ext1(__FILE__); 方法二: function get_ext2($path) { return substr($path,strrpos($path, '.')); } echo get_ext2(__FILE__); 方法三: function get_ext3($path) { $result = pathinfo($path); //ar

ios 获取文件扩展名备忘

NSString *lastComponent = [cachePath lastPathComponent];              NSString *pathLessFilename = [cachePath stringByDeletingLastPathComponent];              NSString *originalPath = [pathLessFilename stringByAppendingPathComponent: lastComponent];