1

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?

2
  • The output of those functions is automatically formatted. Your problem is that you're viewing that output in a browser, which destroys the formatting... Commented 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. Commented Jan 29, 2012 at 3:28

1 Answer 1

1

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

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

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) } }
Looks just like that on my browser (firefox) output -- all mushed together on one line. ???
@tgoneil Try xdebug_var_dump()? There are also a few ini settings discussed in the link.
I just now tried it by running xdebug_var_dump instead of var_dump and it's still all on one line. ???
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!!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.