Debug function

A simple but useful debug function which outputs a variable
/** * 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; } } } //Example: $v = array(1,2,3,array(1,2,3),array('a' => 'foo', 'b' => 'bar')); debug($v);

Url: http://www.jonasjohn.de/snippets/php/debug-function.htm

Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013