Home > Backend Development > PHP Tutorial > PHP function to get the file name and extension of the url string interception path_PHP tutorial

PHP function to get the file name and extension of the url string interception path_PHP tutorial

WBOY
Release: 2016-07-21 15:41:23
Original
1098 people have browsed it

php gets the file name

Copy code The code is as follows:

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

php gets the file extension
Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321203.htmlTechArticlephp gets the file name and copies the code as follows: function retrieve($url) { preg_match('//([^ /]+.[a-z]+)[^/]*$/',$url,$match); return $match[1]; } php gets file extension copy code...
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