note 18130 added to function.var-dump
| From: | bschlaak at web dot de | Date: | Fri, 11 Jan 2002 15:22:20 +0000 |
| Subject: | note 18130 added to function.var-dump | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24670@lists.php.net to get a copy of this message | ||
Sometimes it's useful to send debugging stuff via mail or log it into a file and not to print
it out.
In this cases I always would like to have a "svar_dump()"-function ...
So I wrote one. It could be shorter but I like clear and easy-to-understand code.
"echo svar_dump($foo);" seems to behave exactly like "var_dump($foo);" - if not,
feel free to contact me!
--- 8< ---
function svar_dump($vInput, $iLevel = 1)
{
$sReturn = "";
if (is_int($vInput))
{
$sReturn = "int(".intval($vInput).")\n";
}
else if (is_float($vInput))
{
$sReturn = "float(".doubleval($vInput).")\n";
}
else if (is_string($vInput))
{
$sReturn = "string(";
$sReturn .= strlen($vInput);
$sReturn .= ") \"";
$sReturn .= $vInput;
$sReturn .= "\"\n";
}
else if (is_bool($vInput))
{
$sReturn = "bool(";
$sReturn .= ($vInput) ? "true" : "false";
$sReturn .= ")\n";
}
else if (is_array($vInput))
{
$sIndentExt = "";
for ($i = 1; $i < $iLevel; $i++)
{
$sIndentExt .= " ";
}
// end for ()
$sIndentInt = $sIndentExt." ";
$sReturn = "array(";
$sReturn .= count($vInput);
$sReturn .= ") {\n";
reset($vInput);
while (list($vKey, $vVal) = each($vInput))
{
$sReturn .= $sIndentInt."[";
$sReturn .= (is_int($vKey)) ? "" : "\"";
$sReturn .= $vKey;
$sReturn .= (is_int($vKey)) ? "" : "\"";
$sReturn .= "]=>\n".$sIndentInt;
$sReturn .= svar_dump($vVal, ($iLevel + 1));
}
// end while ()
$sReturn .= $sIndentExt."}\n";
}
// end if ()
return $sReturn;
}
// end function svar_dump()
--- >8 ---
--
http://www.php.net/manual/en/function.var-dump.php
http://master.php.net/manage/user-notes.php?action=edit+18130
http://master.php.net/manage/user-notes.php?action=delete+18130
http://master.php.net/manage/user-notes.php?action=reject+18130