note 96859 modified in function.print-r by danbrown

From: Date: Fri, 19 Mar 2010 15:25:08 +0000
Subject: note 96859 modified in function.print-r by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167199@lists.php.net to get a copy of this message
A simple function to send the output of print_r to firebug. The script creates a dummy console object with a log method for when firebug is disabled/not available. <?php 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>"; } ?> --was-- A simple function to send the output of print_r to firebug. The script creates a dummy console object with a log method for when firebug is disabled/not available. 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>"; } http://php.net/manual/en/function.print-r.php

« previous php.notes (#167199) next »