function fp_html_print_r
Search API
7.x misc.inc | fp_html_print_r($var, $name = "", $cnt = 0, $max_levels = 20) |
6.x misc.inc | fp_html_print_r($var, $name = "", $cnt = 0, |
4.x misc.inc | fp_html_print_r($var, $name = "", $cnt = 0) |
5.x misc.inc | fp_html_print_r($var, $name = "", $cnt = 0, $max_levels = 20) |
Similar to print_r, this will return an HTML-friendly click-to-open system similar in design to Krumo.
1 call to fp_html_print_r()
File
- includes/
misc.inc, line 1702 - This file contains misc functions for FlightPath
Code
function fp_html_print_r($var, $name = "", $cnt = 0, $max_levels = 20) {
$rtn = "";
if ($cnt > $max_levels) {
// Max levels deep. Deeper, and PHP might run
// out of memory or complain.
$rtn .= "<div class='fp-html-print-r-too-deep'>
" . t("Depth too great. To view deeper,
rephrase your fpm() call, starting at this depth.") . "
</div>";
return $rtn;
}
$type = gettype($var);
$rnd = md5(mt_rand(0, 999999) . microtime() . $type . $name);
if ($type == "boolean") {
$var = ($var == TRUE) ? "TRUE" : "FALSE";
}
$count = "";
if ($type == "string") {
$count = " - " . strlen($var) . " " . t("chars");
}
if ($type == "array" || $type == "object") {
if ($type == "array") {
$count = " - " . count($var) . " " . t("elements");
}
if ($type == "object") {
$count = " - " . get_class($var);
}
$rtn .= "<div class='fp-html-print-r-multi-row'>
<div class='fp-html-print-r-selector'
onClick='\$(\"#fp-html-print-r-var-value-$rnd\").toggle(\"medium\");'
>
<span class='fp-html-print-r-var-name'>$name</span>
<span class='fp-html-print-r-var-type'>($type$count)</span>
</div>
<div class='fp-html-print-r-var-value' id='fp-html-print-r-var-value-$rnd' style='display: none;'>";
foreach ($var as $key => $value) {
$rtn .= fp_html_print_r($value, $key, ($cnt + 1), $max_levels);
}
$rtn .= "</div>
</div>";
}
else if ($type == "string" && strlen($var) > 50) {
// If the variable is fairly long, we want to also make it a hide-to-show type field.
$rtn .= "<div class='fp-html-print-r-multi-row'>
<div
onClick='\$(\"#fp-html-print-r-var-value-$rnd\").toggle(\"medium\");'
>
<span class='fp-html-print-r-var-name'>$name</span>
<span class='fp-html-print-r-var-type'>($type$count)</span>
<span class='fp-html-print-r-var-value-abbr'>" . htmlentities(substr($var, 0, 50)) . "...</span>
</div>
<div class='fp-html-print-r-var-value' id='fp-html-print-r-var-value-$rnd' style='display: none;'>
";
$rtn .= htmlentities($var);
$rtn .= "</div></div>";
}
else {
$html_val = $var;
if ($type != "resource") {
$html_val = htmlentities("" . $var);
}
$rtn .= "<div class='fp-html-print-r-single-row'>
<span class='fp-html-print-r-var-name'>$name</span>
<span class='fp-html-print-r-var-type'>($type$count)</span>
<span class='fp-html-print-r-var-value'>$html_val</span>
</div>";
}
return $rtn;
}