推薦函數:
一是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;
}
方法一:
復制代碼 代碼如下:
<?php
$url=$HTTP_SERVER_VARS['REQUEST_URI'];
echo(str_replace('/','',$url));
?>
方法二:
復制代碼 代碼如下:
<?php
$url = $_SERVER['PHP_SELF'];
$filename= substr( $url , strrpos($url , ‘/')+1 );
echo $filename;
?>
方法三:
復制代碼 代碼如下:
<?php
$url = $_SERVER['PHP_SELF'];
$arr = explode( '/' , $url );
$filename= $arr[count($arr)-1];
echo $filename;
?>
方法四:
復制代碼 代碼如下:
<?php
$url = $_SERVER['PHP_SELF'];
$filename = end(explode('/',$url));
echo $filename;
?>