Last active
December 27, 2015 03:48
-
-
Save kijtra/7261743 to your computer and use it in GitHub Desktop.
[PHP] phpの変数の内容をJavaScriptのconsole.log()で出力。消し忘れを防ぐためにconsole.logではなくconsole.warnにしてあります。
This file contains hidden or 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 console_log($data = NULL) { | |
if (!function_exists('json_encode')) { | |
echo '<pre>'; | |
var_dump($data); | |
echo '</pre>'; | |
return false; | |
} | |
$trace = debug_backtrace(); | |
$file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $trace[0]['file']); | |
$line = $trace[0]['line']; | |
$info = $file.' (Line: '.$line.')'; | |
$data = json_encode($data); | |
echo('<script>if("console" in window){console.warn(\'%c'.$info.'\\n\',\'color:#999;\','.$data.');}</script>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment