The requirement of this blog is that I need to take out all the get parameters from an http request such as 127.0.0.1?a=123&b=456&c=789 and string them behind test.com, that is, the final ideal uri should be test.com ?a=123&b=456&c=789
There are two ways to achieve it. It is recommended to google before doing it. I just don’t have google and it leads to rework
$_SERVER["QUERY_STRING"]
Introduction
This is the simplest method, but most people may not be too familiar with this server variable. Please explain it
[html]
$_SERVER["QUERY_STRING"] : Query string
Code
[php]
$base = "test.com";
$str = $_SERVER["QUERY_STRING"];
$uri = $base.$str;
echo $uri;
Effect
$_GET array for loop to string together
Thoughts
When most people encounter this kind of demand, their first reaction should be to use a for loop to GET the array. Just put the string together yourself and write an implementation code to share
Code
[php]
$str = "test.com?";
$count = count($_GET);
$i = 0; www.2cto.com
foreach ($_GET as $key => $value) {
if ($i == $count - 1) {
$str .= $key . "=" . $value;
} else {
$str .= $key . "=" . $value . "&";
}
$i ++;
}
echo $str;
Effect
http://www.bkjia.com/PHPjc/477794.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477794.htmlTechArticleThe requirement of this blog is that I need to make an http request such as 127.0.0.1?a=123b=456c=789 Take out all the get parameters and string them behind test.com, that is, the final ideal uri should be test.c...