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;
}
The other is the PHP replacement URL in the query section of a variable value for example, we want to set the $url in the key=321;
In fact, there are several situations:
$url = ' www.111cn.net/a.php tutorial? key=330′;
or $url= ' www.111cn.net/a.php;
or $url= ' www.111cn.net/a.php?cat=2′;
Wait a minute. Although the situation is many, PHP is very simple to deal with, as follows:
Copy code code as follows:
/* Set a parameter in the URL to a value//"This is a good paragraph."
function Url_set_value ($url, $key, $value)
{
$a =explode ('? ', $url);
$url _f= $a [0];
$query = $a [1];
Parse_str ($query, $arr);
$arr [$key]= $value;
return $url _f. '? '. Http_build_query ($arr);
}
But my replacement is written in this way. Of course it sucks.