理解 print_r 输出
在某些情况下,print_r 的输出非常复杂、冗长且难以阅读,例如对象、嵌套数组、嵌套对象、嵌套数组……
是否有库或工具可以帮助开发人员读取这些信息?类似于 HTML 的 DOM 检查器?
There are cases when the output for print_r is very complicated, long and hard to read, e.g. objects, nesting arrays, nesting objects, nesting arrays,...
Is there library or tools to help developers read this information? Something like the DOM inspector for HTML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在筛选 print_r 输出时经常使用此函数。这是一个非常棒的快速替代方案。
http://www.php.net/manual/en/function .print-r.php#90759 感谢 bob
如果您使用 Drupal(正如标签所暗示的那样),您可以将其放入主题的 template.php 文件中。
I regularly use this function when sifting through print_r output. It's a fantastic quick alternative.
http://www.php.net/manual/en/function.print-r.php#90759 Credit to bob
You can put it in your theme's template.php file if you're using Drupal as the tags imply.
安装 Devel 模块 并使用
dpm()
函数代替print_r
...它将变量(无论是字符串、对象、数组等)的漂亮表示形式打印到标准 Drupal 消息区域中。它利用了精彩的 Krumo 库,并且是完全交互式的(您可以展开/折叠对象/数组)。有些人可能会说为此使用
你将永远不会回去我保证再次使用
print_r
!Install the Devel Module and use the
dpm()
function in place ofprint_r
...it prints out a lovely representation of your variable (whether it be string, object, array, etc.) into the standard Drupal messages area.It makes use of the wonderful Krumo Library and is fully interactive (you can expand/collapse objects/arrays). Some might say to use
<pre>
tags for this (and normally they might be right) but as this solution already exists for Drupal you'd be crazy not to use itYou'll never go back to using
print_r
again I promise!print_r
的手册页有很多可以帮助您的函数注释。例如:
这是我用过几次的:
The manual page for
print_r
has a lot of comments with functions that could help you.For example:
This is the one I used a few times: