PHP获取文件后缀名的几种常用方法总结

WBOY
Release: 2016-06-20 13:01:15
Original
1951 people have browsed it

使用PHP获取文件后缀名的几种常用方法,通过三种不同的方法

获取文件后缀名,分别通过字符串、文件属性及数组等方式实现。

substr()字符串函数实现的方法:

function get_file_type($filename){
	$type = substr($filename, strrpos($filename, ".")+1);
	return $type;
}
Copy after login

使用pathinfo()函数获取文件后缀名:

function get_file_type($filename){
	$type = pathinfo($filename);
	$type = strtolower($type["extension"]);
	return $type;
}
Copy after login

explode()字符串操作函数获取后缀名:

function get_file_type($filename){  
	$type = explode("." , $filename);
	return end($type);
}
Copy after login

实际开发中,建议使用三种其中更熟悉的一种。


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!