Home >Backend Development >PHP Tutorial >php获取url字符串截取路径的文件名和扩展名的函数_php技巧

php获取url字符串截取路径的文件名和扩展名的函数_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-17 09:28:311038browse

php获取文件名

复制代码 代码如下:

function retrieve($url)
{
preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$url,$match);
return $match[1];
}

php获取文件扩展名
复制代码 代码如下:

function getExt($url)
{
$path=parse_url($url);
$str=explode('.',$path['path']);
return $str[1];
}
echo getExt('http://tools.jb51.net/abc/de/fg.php?id=1');
?>
Statement:
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