Console Print In 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: php console log


// 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!');
?>

Example 3: console php


//display message in console

<?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

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable