/[cvs]/nfo/php/libs/net.php.smarty/plugins/modifier.debug_print_var.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.smarty/plugins/modifier.debug_print_var.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Jun 16 21:58:17 2004 UTC (20 years, 1 month ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +29 -18 lines
updated to smarty-2.6.3

1 cvsjoko 1.1 <?php
2 joko 1.2 /**
3     * Smarty plugin
4     * @package Smarty
5     * @subpackage plugins
6     */
7    
8 cvsjoko 1.1
9 joko 1.2 /**
10     * Smarty debug_print_var modifier plugin
11     *
12     * Type: modifier<br>
13     * Name: debug_print_var<br>
14 cvsjoko 1.1 * Purpose: formats variable contents for display in the console
15 joko 1.2 * @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 cvsjoko 1.1 */
22     function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
23     {
24 joko 1.2 $_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>');
25 cvsjoko 1.1 if (is_array($var)) {
26     $results = "<b>Array (".count($var).")</b>";
27     foreach ($var as $curr_key => $curr_val) {
28 joko 1.2 $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
29     $results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
30 cvsjoko 1.1 }
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 joko 1.2 $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
36     $results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
37 cvsjoko 1.1 }
38 joko 1.2 } else if (is_resource($var)) {
39     $results = '<i>'.(string)$var.'</i>';
40     } else if (empty($var) && $var != "0") {
41     $results = '<i>empty</i>';
42 cvsjoko 1.1 } else {
43     if (strlen($var) > $length ) {
44     $results = substr($var, 0, $length-3).'...';
45     } else {
46     $results = $var;
47     }
48 joko 1.2 $results = htmlspecialchars($results);
49     $results = strtr($results, $_replace);
50 cvsjoko 1.1 }
51 joko 1.2 return $results;
52 cvsjoko 1.1 }
53    
54     /* vim: set expandtab: */
55    
56     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed