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
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Mar 21, 2006 3:54 am
or:
Code: Select all
<?php
header('Content-type: plaintext');
print_r($array);
?>
(It might be text/plaintext.. has been a while)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 21, 2006 8:24 am
text/plain
tasteslikepurple
Forum Commoner
Posts: 46 Joined: Thu Jan 26, 2006 3:38 am
Location: Bath, UK
Post
by tasteslikepurple » Tue Mar 21, 2006 9:55 am
here's my function. i have a class full of useful static functions. it's in the class so that it can keep the same print_r name.
inside the class
Code: Select all
Class Functions
{
/**
* does the same as print_r but the output is much nicer to read.
* usage: echo Functions::print_r ($var)
*/
static function print_r ($v)
{
ob_start();
print_r ($v);
$v = "<pre>" . ob_get_contents() . "</pre>";
ob_end_clean ();
return $v;
}
}
Code: Select all
/**
* now the usage is just echo my_print_r ($var);
*/
function my_print_r ($v)
{
ob_start();
print_r ($v);
$v = "<pre>" . ob_get_contents() . "</pre>";
ob_end_clean ();
return $v;
}
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Tue Mar 21, 2006 2:20 pm
What's the need for ob_start?
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Tue Mar 21, 2006 2:51 pm
kinda a lil off topic...
if I include in my header file just the fuction dump outside of any class then how can I call that function from inside of a class? can i declare a function global or somting crazy like that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 21, 2006 2:55 pm
just call it, functions declared in the global space are available for abuse in the object space without escape.
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Tue Mar 21, 2006 3:00 pm
haha, 'abuse', what a great way to describe it
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Mar 21, 2006 3:57 pm
d3ad1ysp0rk wrote: What's the need for ob_start?
I assume it's to avoid priting it directly. There's actually a boolean second paramter fro print_r() however for this purpose
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Tue Mar 21, 2006 7:19 pm
d11wtq wrote: d3ad1ysp0rk wrote: What's the need for ob_start?
I assume it's to avoid priting it directly. There's actually a boolean second paramter fro print_r() however for this purpose
Yeah, that's kinda what I was thinking. =)
I just wanted to double check that their wasn't some other reason
tasteslikepurple
Forum Commoner
Posts: 46 Joined: Thu Jan 26, 2006 3:38 am
Location: Bath, UK
Post
by tasteslikepurple » Wed Mar 22, 2006 11:17 am
d3ad1ysp0rk wrote: d11wtq wrote: d3ad1ysp0rk wrote: What's the need for ob_start?
I assume it's to avoid priting it directly. There's actually a boolean second paramter fro print_r() however for this purpose
Yeah, that's kinda what I was thinking. =)
I just wanted to double check that their wasn't some other reason
just so that it's easier to read
(in my opinion anyway!)
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Mar 22, 2006 1:34 pm
I looks like what tasteslikepurple really wants with the my_print_r() function is a logging class. These are pretty handy because rather than having to deal with the return values, the logging object holds all the output and you can write it to whereever you want, when you want to.
(#10850)
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Wed Mar 22, 2006 8:31 pm
Install XDebug, and then var_dump() even gets color coded. :3