Created
April 10, 2012 07:20
-
-
Save d48/2348993 to your computer and use it in GitHub Desktop.
php debug to javascript console.log
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
| 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>"; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
came across this handy dandy php function. pretty display of php array into console.log