<?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);
}