function boost_print_r in Boost 6
Same name and namespace in other branches
- 7 boost.module \boost_print_r()
An alternative to print_r that unlike the original does not use output buffering with the return parameter set to true. Thus, Fatal errors that would be the result of print_r in return-mode within ob handlers can be avoided. http://php.net/print-r#75872
Comes with an extra parameter to be able to generate html code. If you need a human readable DHTML-based print_r alternative, see http://krumo.sourceforge.net/
Support for printing of objects as well as the $return parameter functionality added by Fredrik (fredrik dot motin at gmail), to make it work as a drop-in replacement for print_r (Except for that this function does not output parenthesis around element groups... ;) )
Based on return_array() By Matthew Ruivo (mruivo at gmail) (http://www.php.net/manual/en/function.print-r.php#73436)
7 calls to boost_print_r()
- boost_block in ./
boost.module - Implementation of hook_block().
- boost_cache_expire_router in ./
boost.module - Expires the static file cache for the given router items.
- boost_cache_kill in ./
boost.module - Deletes cached page from file system.
- boost_cache_set_node_relationships in ./
boost.module - Creates a parent child relationship for pages like views.
- boost_expire_node in ./
boost.module - Expires a node from the cache; including related pages.
File
- ./
boost.module, line 4748 - Provides static file caching for Drupal text output. Pages, Feeds, ect...
Code
function boost_print_r($var, $return = FALSE, $html = FALSE, $level = 0) {
$spaces = "";
$space = $html ? " " : " ";
$newline = $html ? "<br />" : "\n";
for ($i = 1; $i <= 6; $i++) {
$spaces .= $space;
}
$tabs = $spaces;
for ($i = 1; $i <= $level; $i++) {
$tabs .= $spaces;
}
if (is_array($var)) {
$title = "Array";
}
elseif (is_object($var)) {
$title = get_class($var) . " Object";
}
$output = $title . $newline . $newline;
// Recursive boost_print_r
if ($var) {
foreach ($var as $key => $value) {
if (is_array($value) || is_object($value)) {
$level++;
$value = boost_print_r($value, TRUE, $html, $level);
$level--;
}
$output .= $tabs . "[" . $key . "] => " . $value . $newline;
}
}
if ($return) {
return $output;
}
else {
echo $output;
}
}