如何从 URL 中获取所有参数并在 PHP 中打印出来?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2160382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I grab all parameters from a URL and print it out in PHP?
提问by SarmenHB
How do I print out all the parameters and their value from a URL without using e.g. print $_GET['paramater-goes-here'];multiple times?
如何在不print $_GET['paramater-goes-here'];多次使用的情况下从 URL 打印出所有参数及其值?
回答by jab
I use
我用
print_r($_GET);
回答by echo
foreach($_GET as $key => $value){
echo $key . " : " . $value . "<br />\r\n";
}
回答by Pascal MARTIN
回答by Cherry
Its easy to get all request parameters from url.
从 url 获取所有请求参数很容易。
<?php
print_r($_REQUEST);
?>
This will return an array format.
这将返回一个数组格式。
回答by GZipp
You can also use parse_url()and parse_str():
您还可以使用parse_url()和parse_str():
$url = 'http://www.example.com/index.php?a=1&b=2&c=3&d=some%20string';
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query);
parse_str($query, $arr);
echo $query; // a=1&b=2&c=3&d=some%20string
echo $a; // 1
echo $b; // 2
echo $c; // 3
echo $d; // some string
foreach ($arr as $key => $val) {
echo $key . ' => ' . $val . ', '; // a => 1, b => 2, c => 3, d => 4
}
回答by edCoder
Try this.....
尝试这个.....
function get_all_get()
{
$output = "?";
$firstRun = true;
foreach($_GET as $key=>$val) {
if(!$firstRun) {
$output .= "&";
} else {
$firstRun = false;
}
$output .= $key."=".$val;
}
return $output;
}
回答by Cyril Jacquart
i use:
我用:
ob_start();
var_dump($_GET);
$s=ob_get_clean();

