Page 1 of 1

print_r() Showing in 1 line

Posted: Wed Jan 10, 2007 1:06 pm
by neel_basu
I am Using php 5
and Using print_r() But Its Is Showing the results in 1 line

Code: Select all

<?php
    $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
    print_r ($a);
?>
The above code make output

Code: Select all

Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) )
But it should output like this ( according to manual )

Code: Select all

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)
How can I solve It ??

Posted: Wed Jan 10, 2007 1:08 pm
by AKA Panama Jack
You could try...

Code: Select all

echo nl2br(print_r($a, true));

Posted: Wed Jan 10, 2007 1:11 pm
by impulse()
See what

Code: Select all

var_dump
gives you.

Posted: Wed Jan 10, 2007 1:13 pm
by neel_basu
AKA Panama Jack wrote:You could try...

Code: Select all

echo nl2br(print_r($a, true));
Thanks Now I Got It
i see
The print_r function is not Using <br /> it is Using \n and \t
Thanks For Your Replies

Posted: Wed Jan 10, 2007 1:16 pm
by Kieran Huggins
I usually use the large, nasty:

Code: Select all

echo '<pre>';
print_r($a);
echo '</pre>';
It's not sexy, but it works!

I guess you could write your own debugging shorthand functions and include them while you develop, like:

Code: Select all

function pre_print_r($var){
    echo '<pre>';
    print_r($var);
    echo '</pre>';
}