Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Created June 23, 2020 05:36
Show Gist options
  • Select an option

  • Save pavlo-bondarchuk/548063e6391c489037fb91d6938e9a51 to your computer and use it in GitHub Desktop.

Select an option

Save pavlo-bondarchuk/548063e6391c489037fb91d6938e9a51 to your computer and use it in GitHub Desktop.
pretty printing var_dump alt
/**
* Pretty Printing
* https://www.billerickson.net/debug-code-with-pretty-printing/
*/
function ea_pp( $obj, $label = '' ) {
$data = json_encode( print_r( $obj,true ) );
?>
<style type="text/css">
#bsdLogger {
position: fixed;
top: 0;
right: 0px;
border-left: 4px solid #bbb;
padding: 6px;
background: white;
color: #444;
z-index: 999;
font-size: 1.25em;
width: 400px;
height: 100vh;
overflow: scroll;
}
.admin-bar #bsdLogger {
top: 32px;
height: calc( 100vh - 32px );
}
</style>
<script type="text/javascript">
var doStuff = function(){
var obj = <?php echo $data; ?>;
var logger = document.getElementById('bsdLogger');
if (!logger) {
logger = document.createElement('div');
logger.id = 'bsdLogger';
document.body.appendChild(logger);
}
////console.log(obj);
var pre = document.createElement('pre');
var h2 = document.createElement('h2');
pre.innerHTML = obj;
h2.innerHTML = '<?php echo addslashes($label); ?>';
logger.appendChild(h2);
logger.appendChild(pre);
};
window.addEventListener ("DOMContentLoaded", doStuff, false);
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment