Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
Moderator: General Moderators
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Sat Mar 18, 2006 6:15 pm
I love that function, but it's output is so mangled...
I use it extensively when dumping trees, but following an elements path is sometimes quite daunting...
It would be nice if there was a function which formatted a tree in the way a tree should be formatted???
Know of anything?
Cheers
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 6:20 pm
have an example of how a tree is supposed to be rendered?
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Sat Mar 18, 2006 6:21 pm
You are?
Code: Select all
<pre><?php print_r($_SERVER); ?></pre>
Check the snippets I vaguely remember someone posting something.
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Sat Mar 18, 2006 8:22 pm
Buddha443556 wrote: You are?
Code: Select all
<pre><?php print_r($_SERVER); ?></pre>
Check the snippets I vaguely remember someone posting something.
Nice
Thats perfect...thanks a million man...
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Sat Mar 18, 2006 8:23 pm
feyd wrote: have an example of how a tree is supposed to be rendered?
Basically what buddha suggested is what I was after
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sat Mar 18, 2006 8:57 pm
It's output is already in a nested fashion
You just need to view the source (or use <pre> like Buddha did)
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Sun Mar 19, 2006 2:56 am
d11wtq wrote: It's output is already in a nested fashion
You just need to view the source (or use <pre> like Buddha did)
I had seen examples of print_r but never dawned on me to use PRE I always just dumped to screen as is...but PRE does the trick nicely
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Mar 19, 2006 10:32 am
go to view source like d11 suggested, so real need for a <pre> tag, although you can make your own print_r function
Code: Select all
function dump($array) {
echo '<pre>';
print_r($array);
echo '</pre>';
}
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Sun Mar 19, 2006 10:44 am
Yeah, you wouldn't imagine the amount of times I type
Code: Select all
echo "<pre>" . print_r($_POST,true) . "</pre>";
each day.
alex.barylski
DevNet Evangelist
Posts: 6267 Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg
Post
by alex.barylski » Sun Mar 19, 2006 12:11 pm
Jcart wrote: go to view source like d11 suggested, so real need for a <pre> tag, although you can make your own print_r function
Code: Select all
function dump($array) {
echo '<pre>';
print_r($array);
echo '</pre>';
}
Thats exactly what i've done
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Mon Mar 20, 2006 5:20 am
Mine is a little different
Code: Select all
function dump ($v)
{
print "<pre>";
if (!$v)
{
print_r ($_GET);
$v = $_POST;
}
print_r ($v);
print "</pre>";
}
I'm that lazy
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Mon Mar 20, 2006 12:53 pm
I always include a dump() method in my objects
If you wanted to see a print_r() example that handles the recursion there is indeed one in snippets but it's for JavaScript since JS doesn't have anything like that by default
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Mar 20, 2006 6:47 pm
Code: Select all
<?php
echo nl2br(print_r($array, true));
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Mon Mar 20, 2006 9:44 pm
nl2br won't keep the tabs the correct way afaik, so arrays inside arrays become really messy.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 20, 2006 9:49 pm
when I need to do a variable dump on page, it'll often be done like this:
Code: Select all
echo '<pre>' . __FILE__ . '(' . __LINE__ . ")\n" . htmlentities(var_export($var, true), ENT_QUOTES, 'UTF-8') . '</pre>';but that's usually when I go into shotgun-mode on finding a bug.