当前位置:首页 > PHP教程 > PHP高级教程

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

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

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

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

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!