Home > Article > Backend Development > The file name contains illegal content. Summary of the method of obtaining the currently accessed URL file name in PHP.
Recommended functions:
First, PHP gets the URL of the current page: dedecms also uses this
Copy the 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;
}
Copy the code The code is as follows:
$url=$HTTP_SERVER_VARS['REQUEST_URI'];
e cho(str_replace( '/','',$url));
?>
Copy the code The code is as follows:
$url = $_SERVER['PHP_SELF' ];
$filename= substr( $url , strrpos($url , '/')+1 );
echo $filename;
?>
Copy the code The code is as follows:
$url = $_SERVER['PHP_SELF'];
$arr = explode( '/' , $url );
$filename= $arr[count($arr)-1];
echo $filename;
?>
Copy the code The code is as follows:
$url = $_SERVER['PHP_SELF'];
$filename = end( explode('/',$url));
echo $filename;
?>
The above has introduced a summary of the method of obtaining the currently accessed URL file name in PHP if the file name contains illegal content, including the content of the file name containing illegal content. I hope it will be helpful to friends who are interested in PHP tutorials.