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; ?>
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.
I wrote a function (
debug_display
) which can print, arrays, objects, and file info in pretty way.Use
This should work ^^
I really love
var_export()
. If you like copy/paste-able code, try:Or even something like this for color syntax highlighting:
I have make an addition to @AbraCadaver answers. I have included a javascript script which will delete php starting and closing tag. We will have clean more pretty dump.
May be somebody like this too.
Result before:
Result After:
Now we don't have php starting and closing tag
The best what and easiest way to get nice var_dump is use xDebug (must have for any php dev) Debian way install
In console:
apt-get install php-xdebug
after that you should open php.ini (depends on which stack you use) for it's /etc/php/7.0/fpm/php.iniSearch for
display_errors
set same ->
display_errors = On
Check
html_errors
in same file a little bit below, it's also must beOn
Save and exit
After open
/etc/php/7.0/fpm/conf.d/20-xdebug.ini
And add to the end: ``` xdebug.cli_color=1
``` Save and exit.
A lot other available option and documentation for xdebug can be founded here.
https://xdebug.org/docs/
Good luck and Have Fun !!!
Result
Here is my function to have a pretty var_dump. Combined with Xdebug, it helps a lot to have a better view of what we are dumping.
I improved a bit the display of Xdebug (give some space around, separator between values, wrap long variables, etc).
When you call the function, you can set a title, a background, a text color to distinguish all your var_dump in a page.
Or not ;)