Home > Backend Development > PHP Tutorial > Get URL file name suffix_PHP tutorial

Get URL file name suffix_PHP tutorial

WBOY
Release: 2016-07-13 10:25:56
Original
973 people have browsed it

As efficiently as possible, extract the file extension from a standard URL, and then expand the code to get other data, such as directory path. The principle is to use PHP's explode function to separate strings.
For example: http://www.abc.com/abc/de/fg.php?id=1 You need to take out php or .php
It’s very simple, just look at the code.

Copy code The code is as follows:

$url = "http://www.abc .com/abc/de/fg.php?id=1";

//This is written by myself
function getUrl($url) {
$date = explode('?', $url);
$date = basename($date[0]) ;
$date = explode('.', $date);
return $date[1];
}

var_dump(getUrl($url));

//The following two are obtained online
function getExt($url){
$arr = parse_url($url);

$file = basename($arr['path ']);
$ext = explode(".",$file);
return $ext[1];
}

var_dump(getExt($url));

function getName($url) {

$w_param = pathinfo($url);

$str = $w_param['extension'];

list($type, $vars) = explode('?',$str);

return $type;

}
echo 'start3'.date("Y-m-d H:i:s");
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824879.htmlTechArticleAs efficiently as possible, extract the file extension from a standard URL, and then expand the code to get Other data, such as: directory path, the principle is to use PHP's e...
Related labels:
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