-
-
Save ankr/75e181bbb2c566607f13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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