Home  >  Article  >  Backend Development  >  PHP gets all the variable names and values ​​passed in through GET_PHP Tutorial

PHP gets all the variable names and values ​​passed in through GET_PHP Tutorial

WBOY
WBOYOriginal
2016-07-14 10:08:231215browse

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
PHP gets all the variable names and values ​​passed in through GET_PHP Tutorial
$_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
PHP gets all the variable names and values ​​passed in through GET_PHP Tutorial

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn