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

第一种
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') 获取字符串中出现指定字符串的最先位置

第二种

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

第三种

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

第四种

(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/xiaoliwang/p/9308394.html