php 获取当前访问的url文件名的方法小结_PHP教程
程序员文章站
2022-04-04 23:12:32
...
推荐函数:
一是PHP获取当前页面的网址: dedecms也是用的这个
//获得当前的脚本网址
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;
}
方法一:
$url=$HTTP_SERVER_VARS['REQUEST_URI'];
echo(str_replace('/','',$url));
?>
方法二:
$url = $_SERVER['PHP_SELF'];
$filename= substr( $url , strrpos($url , ‘/')+1 );
echo $filename;
?>
方法三:
$url = $_SERVER['PHP_SELF'];
$arr = explode( '/' , $url );
$filename= $arr[count($arr)-1];
echo $filename;
?>
方法四:
$url = $_SERVER['PHP_SELF'];
$filename = end(explode('/',$url));
echo $filename;
?>
一是PHP获取当前页面的网址: dedecms也是用的这个
复制代码 代码如下:
//获得当前的脚本网址
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;
}
方法一:
复制代码 代码如下:
$url=$HTTP_SERVER_VARS['REQUEST_URI'];
echo(str_replace('/','',$url));
?>
方法二:
复制代码 代码如下:
$url = $_SERVER['PHP_SELF'];
$filename= substr( $url , strrpos($url , ‘/')+1 );
echo $filename;
?>
方法三:
复制代码 代码如下:
$url = $_SERVER['PHP_SELF'];
$arr = explode( '/' , $url );
$filename= $arr[count($arr)-1];
echo $filename;
?>
方法四:
复制代码 代码如下:
$url = $_SERVER['PHP_SELF'];
$filename = end(explode('/',$url));
echo $filename;
?>