php 提交表单时如何打印所有 POST 结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9332718/
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 print all POST results when a form is submitted?
提问by Zoolander
I need to see all of the POST
results that are submitted to the server for testing.
我需要查看POST
提交到服务器进行测试的所有结果。
What would be an example of how I can create a new file to submit to that will echo out all of the fields which were submitted with that form?
什么是我如何创建一个新文件提交的示例,该文件将回显使用该表单提交的所有字段?
It's dynamic, so some fields may have a name/ID of field1, field2, field3
, etc.
它是动态的,因此某些字段的名称/ID 可能为field1, field2, field3
等。
回答by Jrod
All the values are stored in the $_POST
collection
所有值都存储在$_POST
集合中
<?php print_r($_POST); ?>
or if you want something fancier that is easier to read use a foreach loop to loop through the $_POST
collection and print the values.
或者,如果您想要一些更容易阅读的更高级的东西,请使用 foreach 循环来遍历$_POST
集合并打印值。
<table>
<?php
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
?>
</table>
回答by Nicolas
Simply:
简单地:
<?php
print_r($_POST);
//Or:
foreach ($_POST as $key => $value)
echo $key.'='.$value.'<br />';
?>
回答by user1074115
You can definitely use var_dump
, but you mentioned you are in front-end development. I am sure you would know this, but just as a reminder, use Firefox's Firebugor Chrome's / Internet Explorer's developers tool and check for the post. Post goes through hearders, and you should be able to check it from there too.
您绝对可以使用var_dump
,但是您提到您从事前端开发。我相信您会知道这一点,但作为提醒,请使用 Firefox 的Firebug或 Chrome 的 / Internet Explorer 的开发人员工具并检查帖子。帖子经过听众,你也应该能够从那里检查它。
回答by Poni
You may mean something like this:
你的意思可能是这样的:
<?php
$output = var_export($_POST, true);
error_log($output, 0, "/path/to/file.log");
?>
回答by Vex
You could use something as simple as this
你可以使用像这样简单的东西
<?php
print_r($_POST);
?>
This would make it a bit more viewable:
这将使它更易于查看:
<?php
echo str_replace(' ', ' ', nl2br(print_r($_POST, true)));
?>
回答by Igor Parra
if (! function_exists('d'))
{
// Debugger
function d($var, $exit = 0)
{
// Only output on localhost
if ($_SERVER['HTTP_HOST'] != 'localhost')
{
return;
}
echo "\n[degug_output_BEGIN]<pre>\n";
echo var_export($var, 1);
echo "\n</pre>[degug_output_END]\n";
if ($exit)
exit;
}
}
// Call:
d($_POST);
Bonus: Check debug_backtrace()too add tracing to your debugging.
奖励:检查debug_backtrace()也将跟踪添加到您的调试中。