Skip to content

Instantly share code, notes, and snippets.

@sdrwtf
Last active October 4, 2021 11:04
Show Gist options
  • Save sdrwtf/ba7bbfc9b5e93a34d82c6c096e123f92 to your computer and use it in GitHub Desktop.
Save sdrwtf/ba7bbfc9b5e93a34d82c6c096e123f92 to your computer and use it in GitHub Desktop.
Simple function to write to dev-tools console log
<?php
// Ment to be used within an existing class
$this->console_log('log me');
/**
* Simple function to write to dev-tools console log
* @param $output Whatever shall be pushed to the log
* @param boolean $with_script_tags Flag to enable <script> tags
*/
private 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment