如何使服务器标头的输出更具可读性?
给定以下 php5 代码,该代码输出大量难以阅读的代码:
<?=var_dump($_SERVER);?>
<?=print_r($GLOBALS); ?>
问题:如何使输出更易于人类阅读?例如,如何将每个“项目”放在新行上?
Given the following php5 code that output a gigantuous amount of difficult to read code:
<?=var_dump($_SERVER);?>
<?=print_r($GLOBALS); ?>
Question: how to make the output more human-readable? e.g. houw to but every "item" on a new line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以只在其周围包裹一个前置元素:
另请注意,
要求将
short_open_tags
设置为 true(在较新版本的 php 中为 false)You can just wrap a pre-element around it:
Also note that
<?=
requiresshort_open_tags
to be set to true (which is false in newer versions of php)在您的开发环境中,您应该安装 Xdebug 扩展。
除了其他有用的功能(例如调试器!),它会让您更好
var_dump()
:例如,这是我为
var_dump($_SERVER);
获得的输出开始的屏幕截图:
(来源:pascal-martin.fr)
On your development environment, you should install the Xdebug extension.
Amongst other useful features (such as a debugger !), it'll get you nicer
var_dump()
:For example, here's a screenshot of the beggining of the output I get for
var_dump($_SERVER);
:(source: pascal-martin.fr)
您可以使用
You can use
<pre>
tag to format the output与其他人提到的一样,您可以将其包装在
Like everyone else mentioned, you can wrap that in
<pre>
tags to make it readable. I usually have the following 2 functions in my code at all times. Used as utility functions, inspired by cake.除了
让事情变得更好更清晰:错误
Apart from the
<pre>
trick, you can try using dbugMakes things much nicer and clearer: dBug
前面的答案提出了很好的解决方案,但是如果您想要对输出进行更多控制,您可以在数组上运行循环。
$_SERVER 和 $_GLOBALS 是数组,因此您
也可以添加 if 语句来忽略 $_SERVER/$_GLOBALS 中的某些项目
the previous answers suggest good solution, but if you want more control on the output you can run a loop over the arrays.
$_SERVER and $_GLOBALS are arrays, so you can do
you can also add if statements to ignore some items in $_SERVER/$_GLOBALS
。
请注意,您的输出之所以巨大只是因为您打印了 $GLOBALS 变量的内容,这对您来说完全无用。
.
Note that your output being gigantic only because you're printing out the contents of $GLOBALS variable, which being completely useless for you.