note 18130 deleted from function.var-dump by sniper

From: Date: Sun, 28 Sep 2003 22:39:17 +0000
Subject: note 18130 deleted from function.var-dump by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57229@lists.php.net to get a copy of this message
Note Submitter: bschlaak@web.de ---- 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 ---

« previous php.notes (#57229) next »