如何在提交表单时打印所有POST结果?

我需要查看提交给服务器进行testing的所有POST结果。

什么是我如何创build一个新的文件提交的例子将回显所有提交的表单的字段?

它是dynamic的,所以一些字段可能有一个名称/ ID为field1, field2, field3

所有的值都存储在$_POST集合中

 <?php print_r($_POST); ?> 

或者如果你想要更容易阅读的东西,可以使用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> 

你可以尝试var_dump :

 var_dump($_POST) 

只是:

 <?php print_r($_POST); //Or: foreach ($_POST as $key => $value) echo $key.'='.$value.'<br />'; ?> 

你可以使用这样简单的东西

 <?php print_r($_POST); ?> 

这将使其更加可视:

 <?php echo str_replace(' ', '&nbsp; ', nl2br(print_r($_POST, true))); ?> 

你绝对可以使用var_dump ,但是你提到你在前端开发。 我相信你会知道这一点,但只是提醒一下,使用Firefox的Firebug或Chrome的/ Internet Explorer的开发工具,并检查后。 邮寄通过听众,你也应该能够从那里检查。

你可能是这样的意思:

 <?php $output = var_export($_POST, true); error_log($output, 0, "/path/to/file.log"); ?> 
 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); 

奖励:检查debug_backtrace()也会将追踪添加到您的debugging中。