Home > Backend Development > PHP Tutorial > Summary of methods for obtaining the currently accessed url file name in php_PHP Tutorial

Summary of methods for obtaining the currently accessed url file name in php_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:41:29
Original
1133 people have browsed it

Recommended functions:
First, PHP gets the URL of the current page: dedecms also uses this

Copy code The code is as follows:

//Get the current script URL
function GetCurUrl()
{
if(!empty($_SERVER["REQUEST_URI"]))
{
$scriptName = $_SERVER[ "REQUEST_URI"];
$nowurl = $scriptName;
}
else
{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER[ "QUERY_STRING"]))
{
$nowurl = $scriptName;
}
else
{
$nowurl = $scriptName."?".$_SERVER["QUERY_STRING" ];
}
}
return $nowurl;
}


Method 1:
Copy code The code is as follows:

$url=$HTTP_SERVER_VARS['REQUEST_URI'];
echo(str_replace('/','', $url));
?>

Method 2:
Copy the code The code is as follows:

$url = $_SERVER['PHP_SELF'];
$filename= substr( $url , strrpos($url , '/')+1 );
echo $filename;
?>

Method three:
Copy code The code is as follows:

$url = $_SERVER['PHP_SELF'];
$arr = explode( '/' , $url );
$filename= $arr[count($ arr)-1];
echo $filename;
?>

Method 4:
Copy code The code is as follows:

$url = $_SERVER['PHP_SELF'];
$filename = end(explode('/',$url));
echo $filename;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321142.htmlTechArticleRecommended functions: First, PHP gets the URL of the current page: dedecms also uses this copy code. The code is as follows: // Get the current script URL function GetCurUrl() { if(!empty($_SERVER["R...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template