Page 2 of 2

Posted: Tue Mar 21, 2006 3:54 am
by Jenk
or:

Code: Select all

<?php

header('Content-type: plaintext');

print_r($array);

?>
:)

(It might be text/plaintext.. has been a while)

Posted: Tue Mar 21, 2006 8:24 am
by feyd
text/plain
;)

Posted: Tue Mar 21, 2006 9:55 am
by tasteslikepurple
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;
	}

Posted: Tue Mar 21, 2006 2:20 pm
by d3ad1ysp0rk
What's the need for ob_start?

Posted: Tue Mar 21, 2006 2:51 pm
by shiznatix
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?

Posted: Tue Mar 21, 2006 2:55 pm
by feyd
just call it, functions declared in the global space are available for abuse in the object space without escape.

Posted: Tue Mar 21, 2006 3:00 pm
by shiznatix
haha, 'abuse', what a great way to describe it

Posted: Tue Mar 21, 2006 3:57 pm
by Chris Corbyn
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 ;)

Posted: Tue Mar 21, 2006 7:19 pm
by d3ad1ysp0rk
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 ;)

Posted: Wed Mar 22, 2006 11:17 am
by tasteslikepurple
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!)

Posted: Wed Mar 22, 2006 1:34 pm
by Christopher
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.

Posted: Wed Mar 22, 2006 8:31 pm
by Ambush Commander
Install XDebug, and then var_dump() even gets color coded. :3