Skip to content

Pretty debug output message in Php (console and html mode)

January 28, 2012
define('CH_TEST', 0) ; // possible value 0,1
define("CH_DEBUG",1) ;
function ch_debug($var,$exit=false,$configable=true){
$templates[] = <<<EOT
<div style='text-align:left;border-top:1px solid #ccc;background-color:white;color:black;overflow:auto;' >
<pre>
<br /> <strong> line : </strong> {line}
<br /> <strong> file : </strong> {file}
<br /> {data}
</pre>
</div>
EOT;
$templates[]= <<<EOT
\n
-------------------------------debug ---------------------------
line : {line}, file : {file}
output: ->
{data}
----------------------------------------------------------------
\n\r
EOT;

if(CH_DEBUG || $exit==true)
{
$debug_traces = debug_backtrace();
$debug_trace=$debug_traces[0];

$str = strtr($templates[CH_TEST],
array( "{line}"=>"{$debug_trace['line']}",
"{file}" => "{$debug_trace['file']}",
"{data}"=> print_r($var, true) //debug_trace['args'][0]
));
echo $str ;
if($exit==true)
exit;
}
}
Advertisements

From → Php

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: