A nice colored output:
echo svar_dump(array("a","b"=>"2","c"=>array("d","e"=>array("f","g"))));
will looks like:
source:
'; else $brs='';
$return = <<{$brs}
|
EOH;
if (is_int($vInput)) {
$return .= gettype($vInput)." (".intval($vInput).") | ";
} else if (is_float($vInput)) {
$return .= gettype($vInput)." (".doubleval($vInput).") ";
} else if (is_string($vInput)) {
$return .= "".gettype($vInput)."(" . strlen($vInput) . ") \"" . _my_html_special_chars($vInput). "\""; #nl2br((_nbsp_replace,
} else if (is_bool($vInput)) {
$return .= gettype($vInput)."(" . ($vInput ? "true" : "false") . ")";
} else if (is_array($vInput) or is_object($vInput)) {
reset($vInput);
$return .= gettype($vInput);
if (is_object($vInput)) {
$return .= " \"".get_class($vInput)."\" Object of ".get_parent_class($vInput);
if (get_parent_class($vInput)=="") $return.="stdClass";
$return.="";
$vInput->class_methods="\n".implode(get_class_methods($vInput),"();\n");
}
$return .= " count = [" . count($vInput) . "] dimension = [{$iLevel}]
";
$return .= <<
EOH;
while (list($vKey, $vVal) = each($vInput)){
$return .= "| ";
$return .= (is_int($vKey)) ? "" : "\"";
$return .= _nbsp_replace(_my_html_special_chars($vKey));
$return .= (is_int($vKey)) ? "" : "\"";
$return .= " | => |
";
if ($iLevel>$maxlevel and is_array($vVal)) $return .= svar_dump("array(".sizeof($vVal)."), but Recursion Level > $maxlevel!!", ($iLevel + 1), $maxlevel);
else if ($iLevel>$maxlevel and is_object($vVal)) $return .= svar_dump("Object, but Recursion Level > $maxlevel!!", ($iLevel + 1), $maxlevel);
else $return .= svar_dump($vVal, ($iLevel + 1), $maxlevel) . " | ";
}
$return .= " |
";
} else {
if (gettype($vInput)=="NULL") $return .="null";
else $return .=gettype($vInput);
if (($vInput)!="") $return .= " (".($vInput).") ";
}
$return .= "";
return $return;
}
function _nbsp_replace($t){
return str_replace(" "," ",$t);
}
function _my_html_special_chars($t,$double_encode=true){
if(version_compare(PHP_VERSION,'5.3.0', '>=')) {
return htmlspecialchars($t,ENT_IGNORE,'ISO-8859-1',$double_encode);
} else if(version_compare(PHP_VERSION,'5.2.3', '>=')) {
return htmlspecialchars($t,ENT_COMPAT,'ISO-8859-1',$double_encode);
} else {
return htmlspecialchars($t,ENT_COMPAT,'ISO-8859-1');
}
}