mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 12:51:38 +01:00
Implemented plugin architecture.
This commit is contained in:
37
libs/plugins/modifier.debug_print_var.php
Normal file
37
libs/plugins/modifier.debug_print_var.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: modifier
|
||||
* Name: debug_print_var
|
||||
* Purpose: formats variable contents for display in the console
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||
{
|
||||
if (is_array($var)) {
|
||||
$results = "<b>Array (".count($var).")</b>";
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$return = smarty_modifier_debug_print_var($curr_val, $depth+1);
|
||||
$results .= '<br>\r'.str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
|
||||
}
|
||||
return $results;
|
||||
} else {
|
||||
if (empty($var)) {
|
||||
return '<i>empty</i>';
|
||||
}
|
||||
if (strlen($var) > $length ) {
|
||||
$results = substr($var, 0, $length-3).'...';
|
||||
} else {
|
||||
$results = $var;
|
||||
}
|
||||
$results = preg_replace("![\r\t\n]!", " ", $results);
|
||||
$results = htmlspecialchars(htmlspecialchars($results));
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user