Page 1 of 1

Substitute for print_r and var_export

Posted: Fri Dec 03, 2004 10:48 am
by Shendemiar
Is there any command or known small nice function that outputs arrays etc. nicely categorized with tabs or emphasized by html.

Posted: Fri Dec 03, 2004 11:22 am
by protokol
You could always write one that parses the values returned from those functions and uses pretty colors.

Posted: Fri Dec 03, 2004 11:31 am
by John Cartwright

Code: Select all

<?php
echo '<pre> '. print_r($array) .'</pre>';
?>
should do it

Posted: Fri Dec 03, 2004 11:44 am
by Shendemiar
protokol wrote:You could always write one that parses the values returned from those functions and uses pretty colors.
That's what i have in mind, but i assumed it's done and used countless times before, so that's why i asked.

Posted: Fri Dec 03, 2004 12:00 pm
by rehfeld

Posted: Fri Dec 03, 2004 12:08 pm
by Shendemiar
That's nice, thanks!

Posted: Fri Dec 03, 2004 1:24 pm
by Shendemiar
I made something handy for printing classes with (multi-D)arrays in them.

Code: Select all

$needles=array( "&#123;" , ";" , "(" , "," , ")" , "&#125;" );
$replace=array( "<BLOCKQUOTE>" , "<BR><BR>" , "<BLOCKQUOTE>" , "<BR>", "</BLOCKQUOTE>" , "</BLOCKQUOTE>");
echo str_replace($needles, $replace, var_export($units,1));
Outputs:

Code: Select all

class cUnits

    public $unit_static = NULL
    public $unit = array

        1 => array

            'type_id' => '1'
            'name_number' => '1'
            'name' => 'Moonguard #1'
            'strength' => '1000'
            'x' => '10'
            'y' => '50'


        2 => array

            'type_id' => '1'
            'name_number' => '2'
            'name' => 'Moonguard #2'
            'strength' => '1000'
            'x' => '11'
            'y' => '50'


        4 => array

            'type_id' => '1'
            'name_number' => '3'
            'name' => 'Combined skirmish force of the Wise'
            'strength' => '0'
            'x' => '0'
            'y' => '0'