Home > Backend Development > PHP Tutorial > How to get file extension via PHP

How to get file extension via PHP

不言
Release: 2023-04-03 08:04:01
Original
2794 people have browsed it

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 Manualphp 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') 获取字符串中出现指定字符串的最先位置
Copy after login

The second type

substr($path, strrpos($path, '.') + 1)
Copy after login

The third type

array_pop(explode('.', $path))
Copy after login

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)
Copy after login

Related article recommendations: 1.
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
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:

Summary of the five principles of PHP object-oriented design (SOLID)

##For PhpStorm code formatting Introduction to settings

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template