This snippet allows you to log things to your browser console. This snippet incorporates the underlying aspects of the native javascript function, but makes it easy to use in your PHP scripts and makes it easy for PHP developers. I usually put this script in a helper.php
file and include it in my index.php
file, which routes every other page.
Then, all you need to do is console_log($dataYouWantToSendToTheConsole);
/**
* Send data via PHP to your Browser's Console
*
* @param $data
*/
function console_log($data) {
$consoleOutput = '<script>' . 'console.log(' . json_encode($data, JSON_HEX_TAG) .');'. '</script>';
echo $consoleOutput;
}
This code snippet was published on It was last edited on