Preface 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 can be implemented in two ways. We recommend that you google it before you do it. I just didn't Google it, causing rework $ _ server ["QUERY_STRING"]
This is the simplest method, but most people may not be familiar with this server variable.
$ _ Server ["QUERY_STRING"]: query string
Code
$ Base = "test.com"; $ STR = $ _ server ["QUERY_STRING"]; $ uri = $ base. $ STR; echo $ URI;
Effect $ _ Get array for loop concatenation ideas most people encounter this kind of requirement. The first response should be the for loop get array. Join the strings yourself and write a code to share the code.
$ STR = "test.com? "; $ COUNT = count ($ _ Get); $ I = 0; foreach ($ _ get as $ key => $ value) {if ($ I = $ count-1) {$ Str. = $ key. "= ". $ value;} else {$ Str. = $ key. "= ". $ value. "&" ;}$ I ++;} echo $ STR;
Although the results are the same, the efficiency of the For Loop is certainly low when there are many get parameters. Therefore, when writing code using PHP, try to make fewer wheels, so I prefer C, so you can move your mind more. Alas, PHP is a silly language, but it is really convenient!