Quick Variable Dump (HTML-friendly)





21
Date Submitted Thu. Aug. 31st, 2006 1:36 PM
Revision 1 of 1
Helper dohpaz
Tags debug | HTML | PHP | Variable
Comments 0 comments
A quick and simple function to dump a variable (array, object, string, int, etc) out into -formatted output for a web browser.

If the variable is an array or an object, you can have it returned into the another variable for later processing (i.e., through templates or e-mail). Due to lack of free time, if the variable is not an array or an object, it will ignore the $return value and print directly to output.

Future revisions will add the above mentioned functionality.

function my_var_dump($variable, $return = FALSE) {
    if (is_array($variable) || is_object($variable)) {
        if ($return == TRUE) {
            return sprintf("<pre>%s</pre>", print_r($variable, true));
        } else {
            printf("<pre>%s</pre>", print_r($variable, true));
            return TRUE;
        }
    } else {
        echo "<pre>";
        var_dump($variable);
        echo "</pre>";
    }
}
 

Ken S

Comments

There are currently no comments for this snippet.

Voting