function dd($value, $return = false){
ini_set('highlight.string', '#99CF50');
ini_set('highlight.keyword', '#555555');
ini_set('highlight.default', '#2980B9');
ini_set('highlight.comment', '#999999');
$highlight_bg = '#f2f2f2';
// styles & button
$id = preg_replace("/\d/", '', md5(rand()));
$output = '<style>#'.$id.'{background:'.($highlight_bg!=''?$highlight_bg:'transparent').'; padding:20px;max-height: 93%; overflow-y: auto; margin-top: 10px;margin-bottom: 30px;}'.'code{word-wrap:break-word;}</style>';
if(is_array($value)||is_object($value)){
function add_slashes(&$var){
switch(true){
case is_object($var) || is_array($var):
foreach($var as &$v){
add_slashes($v);
}
break;
default:
$var = "'".str_replace("'", "`", $var)."'";
break;
}
}
add_slashes($value);
$value_str = print_r($value, true);
$d_c = ini_get('highlight.default');
$k_c = ini_get('highlight.keyword');
$output .= '<div id="'.$id.'">'.preg_replace("/\[(class|default)\]/",
"[</span><span style='color:".$d_c
.";'>$1</span><span style='color:".$k_c.";'>]",
highlight_string('<?php '.$value_str, true)).'</div>';
}else{
$output .= '<div id="'.$id.'">'.highlight_string($value, true).'</div>';
}
$trace = debug_backtrace(false);
$offset = (@$trace[2]['function'] === 'dump_d') ? 2 : 0;
echo '<span style="color:black;">'.@$trace[0+$offset]['file'].':<span style="color: red">'.@$trace[0+$offset]['line'].'</span></span>';
echo $output;
if($return == false){die();}
}
Function to replace a normal print_r(), this beautiffies the code printed and get some code highlights.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.