print_r() Showing in 1 line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

print_r() Showing in 1 line

Post 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 ??
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

You could try...

Code: Select all

echo nl2br(print_r($a, true));
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

See what

Code: Select all

var_dump
gives you.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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>';
}
Post Reply