Skip to content

Instantly share code, notes, and snippets.

@ankr
Forked from kimegede/debug.php
Created June 13, 2014 08:03
Show Gist options
  • Save ankr/75e181bbb2c566607f13 to your computer and use it in GitHub Desktop.
Save ankr/75e181bbb2c566607f13 to your computer and use it in GitHub Desktop.
<?php
function debug($data) {
$bt = debug_backtrace();
$bt = array_shift($bt);
$data = print_r($data, true);
$html = <<<HTML
<div class="debug-output">
%s
<pre class="debug">%s</pre>
</div>
HTML;
$text = <<<TEXT
########## DEBUG ########## -> %s
%s
###########################
TEXT;
if (php_sapi_name() === 'cli') {
$template = $text;
$lineInfo = sprintf('%s (line %s)', $bt['file'], $bt['line']);
} else {
$template = $html;
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $bt['file'], $bt['line']);
}
printf($template, $lineInfo, $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment