使var_dump看起来很漂亮 [英] Make var_dump look pretty

查看:323
本文介绍了使var_dump看起来很漂亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的$_GET[]查询变量集,用于在从数据库中提取查询时显示测试数据.

I have a simple $_GET[] query var set for showing testing data when pulling down queries from the DB.

<?php if($_GET['test']): ?>
  <div id="test" style="padding: 24px; background: #fff; text-align: center;">  
    <table>
      <tr style="font-weight: bold;"><td>MLS</td></tr>
      <tr><td><?php echo KEY; ?></td></tr>
      <tr style="font-weight: bold;"><td>QUERY</td></tr>
      <tr><td><?php echo $data_q; ?></td></tr>
      <tr style="font-weight: bold;"><td>DATA</td></tr>
      <tr><td><?php var_dump($data); ?></td></tr>
    </table>    
</div>
<?php endif; ?>

当我做var_dump时,正如预期的那样,这是大数组字符串,它们都被弄脏了.是否有至少为此添加换行符或以更易读的方式显示var_dump的方法?公开后,我愿意接受有关处理字符串的jQuery建议.

When I do var_dump, as expected it's this big array string that is all smushed together. Is there a way to add in line breaks at least for this or display the var_dump in a way that's more readable? I'm open to jQuery suggestions on manipulating the string after it's posted.

推荐答案

我真的很喜欢var_export().如果您喜欢可复制/粘贴的代码,请尝试:

I really love var_export(). If you like copy/paste-able code, try:

echo '<pre>' . var_export($data, true) . '</pre>';

甚至是这样的颜色语法高亮显示:

Or even something like this for color syntax highlighting:

highlight_string("<?php\n\$data =\n" . var_export($data, true) . ";\n?>");

您可以使用print_r()执行相同的操作.对于var_dump(),您只需添加<pre>标记:

You can do the same with print_r(). For var_dump() you would just need to add the <pre> tags:

echo '<pre>';
var_dump($data);
echo '</pre>';

这篇关于使var_dump看起来很漂亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆