使var

编程入门 行业动态 更新时间:2024-10-18 22:35:23
本文介绍了使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

本文发布于:2023-11-07 23:10:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:var

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!