PHP:如何在php post方法中获取所有变量名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9771389/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:36:08  来源:igfitidea点击:

PHP : How to get all variable name in php post method

php

提问by Lotuspandiyan

I would like to get and display all variable names which are posted by method="post"in a form. I am not aware of variables which passed from post method in HTML. Is there any method to list the all variables posted by post method ?.. Thanks in advance.

我想获取并显示method="post"在表单中发布的所有变量名称。我不知道从 HTML 中的 post 方法传递的变量。有没有任何方法可以列出 post 方法发布的所有变量? .. 提前致谢。

example: http://www.dhamu.in/oncreate2.php?workload=10&request_type=project&name=web%20design&description=we%20have%20done%20it&budget=1&bidperiod=11&project_guidelines=checked&job_113=1&xxxx=10Here i do no the variable name "xxxx"

例如:http: //www.dhamu.in/oncreate2.php?workload=10&request_type=project&name =web%20design & description=we%20have% 20done%20it&budget =1&bidperiod=11&project_guidelines =checked&job_113 =1&xxxx =10这里我不做变量名“xxx”

回答by Brad Christie

foreach ($_POST as $key => $value){
  echo "{$key} = {$value}\r\n";
}

And BTW, those are $_GETvariables (so adjust the above to use foreach ($_GET as $key => $value){.) You can also use $_REQUESTto cover both.

顺便说一句,这些是$_GET变量(因此请调整上述内容以使用foreach ($_GET as $key => $value){。)您也可以使用$_REQUEST来涵盖两者。

回答by iambriansreed

Try:

尝试:

print_r(array_keys($_POST))

print_r(array_keys($_POST))

... for just the keys.

... 只为钥匙。

Or:

或者:

print_r($_POST)

print_r($_POST)

... for all the POST keys and values.

...对于所有 POST 键和值。

回答by Christian Strempfer

To output all POST variables, try this:

要输出所有 POST 变量,请尝试以下操作:

var_dump($_POST);

Variables which are included within the URL are GET variables actually:

URL 中包含的变量实际上是 GET 变量:

var_dump($_GET);