Skip to content

Instantly share code, notes, and snippets.

@d48
Created April 10, 2012 07:20
Show Gist options
  • Save d48/2348993 to your computer and use it in GitHub Desktop.
Save d48/2348993 to your computer and use it in GitHub Desktop.
php debug to javascript console.log
function debug ($data) {
echo "<script>\r\n//<![CDATA[\r\nif(!console){var console={log:function(){}}}";
$output = explode("\n", print_r($data, true));
foreach ($output as $line) {
if (trim($line)) {
$line = addslashes($line);
echo "console.log(\"{$line}\");";
}
}
echo "\r\n//]]>\r\n</script>";
}
@d48
Copy link
Author

d48 commented Apr 11, 2012

came across this handy dandy php function. pretty display of php array into console.log

Sample output to console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment