如何获取帖子中的所有变量 (PHP)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3058336/
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 to grab all variables in a post (PHP)
提问by ilhan
How to grab all variables in a post (PHP)?
I don't want to deal with $_POST['var1']; $_POST['var2']; $_POST['var3']; ...I want to echo all of them in one shot.
如何获取帖子(PHP)中的所有变量?我不想处理$_POST['var1']; $_POST['var2']; $_POST['var3']; ...我想一次回应所有这些。
回答by CaseySoftware
If you really just want to print them, you could do something like:
如果您真的只想打印它们,您可以执行以下操作:
print_r($_POST);
Alternatively, you could interact with them individually doing something like:
或者,您可以通过以下方式与他们单独互动:
foreach ($_POST as $key => $value) {
//do something
echo $key . ' has the value of ' . $value;
}
but whatever you do.. please filter the input. SQL Injection gives everyone sleepless nights.
但无论你做什么.. 请过滤输入。SQL 注入让每个人彻夜难眠。
回答by Pacific Voyager
If you want the POST values as variables in your script, you can use the extract function, e.g.
如果您希望 POST 值作为脚本中的变量,您可以使用提取函数,例如
extract ( $_GET );
or
或者
extract ( $_GET, EXTR_IF_EXISTS );
There are several flags you can use (check the manual); this one restricts extraction to variables already defined.
您可以使用几个标志(查看手册);这将提取限制为已定义的变量。
You can also use the import_request_variables function.
您还可以使用 import_request_variables 函数。
Cheers
干杯
Jeff
杰夫
回答by Fernando Briano
Use:
用:
var_dump($_POST);
回答by Russell Dias
echo '<pre>';
print_r($_POST);
echo '</pre>';
回答by Yasir
Use this function in a loop. extract ( $_GET );
在循环中使用此函数。提取( $_GET );

