how to write in console php code example

Example 1: php console log

// Assuming you are wishing to log to the JS Console...

<?php
	function consoleLog($msg) {
		echo '<script type="text/javascript">' .
          'console.log(' . $msg . ');</script>';
	}

	consoleLog('Hello, console!');
?>

Example 2: console php

//display message in console

<?php
	function console_log($msg) {
		echo '<script>' .
          'console.log("'.$msg .' ")</script>';
	}

	console_log("Hi there!");
?>

Example 3: console_log in php

<?php
function console_log($output, $with_script_tags = true) {
    $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . 
');';
    if ($with_script_tags) {
        $js_code = '<script>' . $js_code . '</script>';
    }
    echo $js_code;
}

Tags:

Php Example