print_r alternative???

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

User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

or:

Code: Select all

<?php

header('Content-type: plaintext');

print_r($array);

?>
:)

(It might be text/plaintext.. has been a while)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

text/plain
;)
User avatar
tasteslikepurple
Forum Commoner
Posts: 46
Joined: Thu Jan 26, 2006 3:38 am
Location: Bath, UK

Post 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;
	}
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

What's the need for ob_start?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

just call it, functions declared in the global space are available for abuse in the object space without escape.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

haha, 'abuse', what a great way to describe it
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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 ;)
User avatar
tasteslikepurple
Forum Commoner
Posts: 46
Joined: Thu Jan 26, 2006 3:38 am
Location: Bath, UK

Post 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!)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Install XDebug, and then var_dump() even gets color coded. :3
Post Reply