Created
August 16, 2019 12:27
-
-
Save millsoft/7a379d3a25db908a6336695d28af9a80 to your computer and use it in GitHub Desktop.
console.log for php print php Variables in Browser console
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) | |
{ | |
$bt = debug_backtrace(); | |
$caller = array_shift($bt); | |
$caller_string = "{$caller['file']}:{$caller['line']}"; | |
$d = json_encode($data); | |
$html = <<<html | |
<script> | |
/* {$caller_string} */ | |
console.log({$d}); | |
</script> | |
html; | |
echo $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment