Is there a php.ini setting (or some other setting) that will cause print_r and var_dump output to be automatically formatted as though I had explicitly placed a <pre> tag before such an output statement?
-
The output of those functions is automatically formatted. Your problem is that you're viewing that output in a browser, which destroys the formatting...deceze– deceze ♦2012-01-29 03:08:43 +00:00Commented Jan 29, 2012 at 3:08
-
But I've seen it done, so I know it's possible to have the browser show desired formatting.tgoneil– tgoneil2012-01-29 03:28:27 +00:00Commented Jan 29, 2012 at 3:28
Add a comment
|
1 Answer
I don't know of any way to do this within PHP but I know xdebug replaces PHP's normal var_dump and it looks pretty awesome.
Here's an example
$object = new stdClass();
$object->xdebug = 'http://www.xdebug.org/';
$object->vardump = 'Looks awesome now';
$int = 1;
$str = 'Stack Overflow';
$array = array(0 => 'foo', 1 => 'bar', '2' => 'baz');
var_dump($object);
var_dump($int);
var_dump($str);
var_dump($array);
results in

8 Comments
tgoneil
I have xdebug and phpstorm running with php. When running the test script from the link you provided, the results are:array(4) { ["one"]=> string(23) "a somewhat long string!" ["two"]=> array(1) { ["two.one"]=> array(2) { ["two.one.zero"]=> int(210) ["two.one.one"]=> array(2) { ["two.one.one.zero"]=> float(3.141592564) ["two.one.one.one"]=> float(2.7) } } } ["three"]=> object(test)#1 (3) { ["pub"]=> RECURSION ["priv":"test":private]=> bool(true) ["prot":protected]=> int(42) } ["four"]=> array(6) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) } }
tgoneil
Looks just like that on my browser (firefox) output -- all mushed together on one line. ???
Charles Sprayberry
@tgoneil Try
xdebug_var_dump()? There are also a few ini settings discussed in the link.tgoneil
I just now tried it by running xdebug_var_dump instead of var_dump and it's still all on one line. ???
tgoneil
Ok found the problem. Amazingly, the info was indeed found in the XDebug documentation about html_errors setting. Turns out my php.ini file had html_errors=Off. Changed it On and voila! THANK YOU CHARLES!!!
|