home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / modifier.debug_print_var.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  1.8 KB  |  57 lines

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8.  
  9. /**
  10.  * Smarty debug_print_var modifier plugin
  11.  *
  12.  * Type:     modifier<br>
  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.  * @param array|object
  18.  * @param integer
  19.  * @param integer
  20.  * @return string
  21.  */
  22. function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
  23. {
  24.     if (is_array($var)) {
  25.         $results = "<b>Array (".count($var).")</b>";
  26.         foreach ($var as $curr_key => $curr_val) {
  27.             $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  28.             $results .= '<br>\r'.str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
  29.         }
  30.         return $results;
  31.     } else if (is_object($var)) {
  32.         $object_vars = get_object_vars($var);
  33.         $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
  34.         foreach ($object_vars as $curr_key => $curr_val) {
  35.             $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  36.             $results .= '<br>\r'.str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
  37.         }
  38.         return $results;
  39.     } else {
  40.         if (empty($var) && $var != "0") {
  41.             return '<i>empty</i>';
  42.         }
  43.         if (strlen($var) > $length ) {
  44.             $results = substr($var, 0, $length-3).'...';
  45.         } else {
  46.             $results = $var;
  47.         }
  48.         $results = preg_replace("![\r\t\n]!", " ", $results);
  49.         $results = htmlspecialchars($results);
  50.         return $results;
  51.     }
  52. }
  53.  
  54. /* vim: set expandtab: */
  55.  
  56. ?>
  57.