Php obtains the names and values of all variables passed in the GET method. The requirement of this blog is that I need to send an http request such as 127.0.0.1? A123b456c789 obtain all the get parameters and concatenate them to the end of test.com. that is, the final ideal uri should be test. c. the requirement of this blog is that I need to send an http request such as 127.0.0.1? A = 123 & B = 456 & c = 789 obtain all the get parameters and concatenate them to the end of test.com. that is, the final ideal uri should be test.com? A = 123 & B = 456 & c = 789
Two methods can be implemented. we recommend that you google it before you do it. I just didn't google it, causing rework.
$ _ SERVER ["QUERY_STRING"]
Introduction
This is the simplest method, but most people may not be familiar with this server variable.
[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 concatenation
Ideas
Most people encounter this requirement. The first response should be the for loop GET array. join the strings and write a shared code.
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
Why? A = 123b = 456c = 789 obtain all the get parameters and concatenate them to the end of test.com. that is, the final ideal uri should be test. c...