// 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!');
?>
<?php
$message = "Thanks..";
echo "<script>console.log('".$message."');</script>";
?>
Output: Thanks..
echo("<script type='text/javascript'> console.log($msg);</script>");
// A little correction / improvement to @Kaotik's answer:
<?php
function consoleLog($msg)
{
echo '<script type="text/javascript">console.log('
. str_replace('<', 'x3C', json_encode($msg))
. ');</script>';
}
consoleLog('Hello, console!');
?>
<script>
console.log(<?= json_encode($foo); ?>);
</script>
<?php
function consoleLog($msg) {
echo '<script type="text/javascript">console.log('. $msg .');</script>';
}
consoleLog("'Hello world!'");
?>
$a = array(
null => 'a',
true => 'b',
false => 'c',
0 => 'd',
1 => 'e',
'' => 'f'
);
echo count($a), "
";