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

WBOY
WBOYOriginal
2016-07-21 15:41:291117browse

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:
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