php获取文件扩展名

<?php

$path = 'http://www.wstmart.net/doc.html';
$ext = getExt($path);
echo $ext;

// 方法1
function getExt($path){
	$arr = parse_url($path);
	$filename = basename($arr['path']);
	$ext = '.'.explode('.',$filename)[1];
	return $ext;
}

// 方法2
function getExt($path){
	return strrchr($path,'.');
}

// 方法3
function getExt($path){
	return substr($path,strrpos($path,'.'));
}

// 方法4
function getExt($path){
	return pathinfo($path)['extension'];
}

// 方法5
function getExt($path){
	return pathinfo($path, PATHINFO_EXTENSION);
}
posted @ 2019-02-12 18:06  pine007  阅读(155)  评论(0编辑  收藏  举报