Last active
July 28, 2016 12:50
-
-
Save CroModder/f191a7b30dfca2711a9ed2391c37efa0 to your computer and use it in GitHub Desktop.
debug2Console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://stackoverflow.com/questions/4323411/how-can-i-write-to-console-in-php#answer-37218530 | |
* Simple helper to debug to the console | |
* | |
* @param $data object, array, string $data | |
* @param $context string Optional a description. | |
* | |
* @return string | |
*/ | |
function debug_to_console( $data, $context = 'Debug in Console' ) { | |
// Buffering to solve problems frameworks, like header() in this and not a solid return. | |
ob_start(); | |
$output = 'console.info( \'' . $context . ':\' );'; | |
$output .= 'console.log(' . json_encode( $data ) . ');'; | |
$output = sprintf( '<script>%s</script>', $output ); | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment