10 * Smarty debug_print_var modifier plugin
13 * Name: debug_print_var<br>
14 * Purpose: formats variable contents for display in the console
15 * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
16 * debug_print_var (Smarty online manual)
17 * @author Monte Ohrt <monte at ohrt dot com>
23 function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
25 $_replace = array("\n"=>'<i>\n</i>', "\r"=>'<i>\r</i>', "\t"=>'<i>\t</i>');
27 $results = "<b>Array (".count($var).")</b>";
28 foreach ($var as $curr_key => $curr_val) {
29 $return = smarty_modifier_debug_print_var($curr_val, $depth+
1, $length);
30 $results .= "<br>".str_repeat(' ', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> => $return";
32 } else if (is_object($var)) {
33 $object_vars = get_object_vars($var);
34 $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
35 foreach ($object_vars as $curr_key => $curr_val) {
36 $return = smarty_modifier_debug_print_var($curr_val, $depth+
1, $length);
37 $results .= "<br>".str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
39 } else if (is_resource($var)) {
40 $results = '<i>'.(string)$var.'</i>';
41 } else if (empty($var) && $var != "0") {
42 $results = '<i>empty</i>';
44 if (strlen($var) > $length ) {
45 $results = substr($var, 0, $length-3).'...';
49 $results = htmlspecialchars($results);
50 $results = strtr($results, $_replace);
55 /* vim: set expandtab: */