Example 1: php console log
<?php
function consoleLog($msg) {
echo '<script type="text/javascript">' .
'console.log(' . $msg . ');</script>';
}
consoleLog('Hello, console!');
?>
Example 2: php console log
<?php
function consoleLog($msg)
{
echo '<script type="text/javascript">console.log('
. str_replace('<', '\\x3C', json_encode($msg))
. ');</script>';
}
consoleLog('Hello, console!');
?>
Example 3: console php
<?php
function console_log($msg) {
echo '<script>' .
'console.log("'.$msg .' ")</script>';
}
console_log("Hi there!");
?>
Example 4: 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;
}
Example 5: php print to console
<script>
console.log(<?= json_encode($foo); ?>);
</script>
Example 6: php console print
$a = array(
null => 'a',
true => 'b',
false => 'c',
0 => 'd',
1 => 'e',
'' => 'f'
);
echo count($a), "\n";
Comments
Post a Comment