php 打印帖子值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/196664/
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
Print out post values
提问by Brad
I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value.
我有一个包含多个字段的表单,出于测试目的,有没有一种方法可以打印出在所有字段中输入的值,而不必单独打印每个值。
回答by defeated
You should be able to do a var_dump($_REQUEST);
你应该能够做一个 var_dump($_REQUEST);
http://us2.php.net/manual/en/reserved.variables.request.php
http://us2.php.net/manual/en/reserved.variables.request.php
回答by micahwittman
print_r()/ var_dump()are simple and gets the job done.
print_r()/var_dump()很简单,可以完成工作。
If you want a styled/dynamic option check out Krumo:
如果您想要样式/动态选项,请查看Krumo:
A lot of developers use
print_r()andvar_dump()... Krumo is an alternative: it does the same job, but it presents the information beautified using CSS and DHTML.
许多开发人员使用
print_r()和var_dump()... Krumo 是另一种选择:它做同样的工作,但它呈现使用 CSS 和 DHTML 美化的信息。
回答by Paolo Bergantino
For extra credit, I always have:
对于额外的信用,我总是有:
function pre($data) {
print '<pre>' . print_r($data, true) . '</pre>';
}
Whenever I need to debug an array - which is very often - I just do pre($arr); to get a nicely formatted dump.
每当我需要调试一个数组时——这很常见——我只做 pre($arr); 获得格式良好的转储。
回答by ajmakoni
If you pay close attention to the $_POST[]or $_GET[]method, you will realize that both of them are actually arrays.This means that you can play around with them just like you do with any other arrays.
如果您密切关注$_POST[]or$_GET[]方法,您会发现它们实际上都是数组。这意味着您可以像处理任何其他数组一样使用它们。
For example, you can print_r($_POST)and you will see everything the way were entered..
例如,您可以print_r($_POST)并且您将看到输入的所有内容。
回答by Rinzler
I basically use:
我基本上使用:
echo "<pre>"; print_r($_POST) ; echo "</pre>";
It prints the post values in a nice formatted way.
它以一种很好的格式化方式打印帖子值。
回答by Tim
This PHP code doesn't require any knowledge of the fields in the form that submits to it, it just loops through all of the fields, including multiple-choice fields (like checkboxes), and spits out their values.
这个 PHP 代码不需要任何关于提交给它的表单中的字段的知识,它只是循环遍历所有字段,包括多项选择字段(如复选框),并吐出它们的值。
<?php
// loop through every form field
while( list( $field, $value ) = each( $_POST )) {
// display values
if( is_array( $value )) {
// if checkbox (or other multiple value fields)
while( list( $arrayField, $arrayValue ) = each( $value ) {
echo "<p>" . $arrayValue . "</p>\n";
}
} else {
echo "<p>" . $value . "</p>\n";
}
}
?>
回答by Rexxars
回答by Tyler Mecham
This shows more than just POST variables, but it's about as easy as it gets.
这不仅显示了 POST 变量,而且也很简单。
<?php
phpinfo(INFO_VARIABLES);
?>
回答by Hermooz
Besides using inline debug statements, you could also considering transient debugging, i.e. you could use an IDE with debug capabilities, like eclipse or zend studio. This way you could watch any variable you'd like to.
除了使用内联调试语句,您还可以考虑瞬时调试,即您可以使用具有调试功能的 IDE,例如 eclipse 或 zend studio。这样你就可以观察任何你想要的变量。
bye!
再见!
回答by Mar Taylor
Very simply,
很简单,
phpinfo();
It includes a listing of all variables passed to PHP from a form, in an easy-to-read format.
它以易于阅读的格式列出了从表单传递给 PHP 的所有变量。

