Skip to content

Instantly share code, notes, and snippets.

@flydev-fr
Last active September 1, 2016 22:05
Show Gist options
  • Save flydev-fr/cc4589be264889cfac6bd2b928b046d7 to your computer and use it in GitHub Desktop.
Save flydev-fr/cc4589be264889cfac6bd2b928b046d7 to your computer and use it in GitHub Desktop.
debug function, outptut in console dev. browser
<?php
// debug function
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>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment