This article mainly introduces how to obtain the file extension through PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Recommended Manual :php complete self-study manual
##The first type
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') 获取字符串中出现指定字符串的最先位置
The second type
substr($path, strrpos($path, '.') + 1)
The third type
array_pop(explode('.', $path))
The fourth type
(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)
Related article recommendations: 1.The above is the entire content of this article, I hope it will be helpful to everyone’s learning, more related Please pay attention to the PHP Chinese website for content! Related recommendations:
Several methods for PHP to determine and obtain file extensions 2.
Various methods for PHP to obtain file extensions
Related video recommendations:
1. Dugu Jiujian (4)_PHP video tutorial
Summary of the five principles of PHP object-oriented design (SOLID)
The above is the detailed content of How to get file extension via PHP. For more information, please follow other related articles on the PHP Chinese website!