Debug function

A simple but useful debug function which outputs a variable

Snippet information

Author:
Carlos Reche (found in an php.net comment)

License:
?

Language:
PHP

Created:
04/05/2006

Updated:
04/05/2006

Tags:


/**
 * void debug ( mixed Var [, bool Exit] )
 *
 * Carlos Reche
 * Jan 14, 2006
 */
 
if (!function_exists("debug")) {
 
    function debug($var, $exit = false) {
        echo "\n<pre>";
 
        if (is_array($var) || is_object($var)) {
            echo htmlentities(print_r($var, true));
        } 
        elseif (is_string($var)) {
            echo "string(" . strlen($var) . ") \"" . htmlentities($var) . "\"\n";
        } 
        else {
            var_dump($var);
        }
        echo "</pre>";
 
        if ($exit) {
            exit;
        }
    }
}


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment