Home > php教程 > php手册 > php获取GET方式传入的全部变量名称与值

php获取GET方式传入的全部变量名称与值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:54:25
Original
1227 people have browsed it

这篇博客的需求是我需要将一个http请求例如127.0.0.1?a=123&b=456&c=789将所有的get参数取出来拼串到test.com后面,也就是最后理想的uri应该是test.com?a=123&b=456&c=789

两种方法可以实现,建议做之前先google,我就是没有google导致返工

 

$_SERVER["QUERY_STRING"]

 

简介

这是最简单的方法,可是大部分人可能不会太熟悉这个服务器变量,解释一下

[html] 

$_SERVER["QUERY_STRING"] : 查询的字符串  

 

代码

[php]  

$base = "test.com";  

$str = $_SERVER["QUERY_STRING"];  

$uri = $base.$str;  

echo $uri;  

 

效果

 

 

$_GET数组for循环拼串

 

思路

大部分人遇到这种需求第一反应都应该是for循环GET数组,自己拼串吧,写个实现代码共享一下

 

代码

[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;  

 

效果

 

source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template