note 96979 deleted from function.var-dump by danbrown
| From: | danbrown@php.net | Date: | Thu, 25 Mar 2010 18:50:53 +0000 |
| Subject: | note 96979 deleted from function.var-dump by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167417@lists.php.net to get a copy of this message | ||
Note Submitter: office at gt3 dot ro
----
If you want some fancy var_dump, here it goes:
[CODE]
function dbg($vars, $die = 0)
{
$vars = explode(',', $vars);
if(sizeof($vars)) foreach($vars as $var)
{
$varname = trim($var);
if($varname[0] == "$")
$varname = substr($varname, 1);
global ${$varname};
$varvalue = ${$varname};
if(is_Array($varvalue))
$output = print_r($varvalue, true);
else
$output = $varvalue;
ob_start();
var_dump($varvalue);
$varDump=ob_get_contents();
ob_end_clean();
echo '<pre style="background-color:#eeeeee; margin-bottom: 5px; border:3px
blue double"><b style="color:#ff0000"><b>Standard output of [<font
style="color:green">$' . $varname . '</font>]
:</b><br>' . $output . '<hr><b>VarDump of [<font
style="color:green">$' . $varname . '</font>]
:</b><br>' . htmlspecialchars($varDump, ENT_QUOTES) . '</pre>';
}
if($die) die(); // :)
}
[/CODE]
USAGE:
$a = array(1, 2, 3);
$b = 'test';
$c = rand(0,5);
dbg('a,b,c');
Or if after debbuging die() is needed:
dbg('a,b,c', true);