Prettier PHP Debug Messages continued

Continuation to Prettier PHP Debug Messages. This version is self-styling and also accepts a label parameter.

if (!function_exists('pp')) { //Pretty Print
  function pp($obj,$label = '') {  
    $data = json_encode(print_r($obj,true));
    <style type="text/css">
      #bsdLogger {
      position: absolute;
      top: 0px;
      right: 0px;
      border-left: 4px solid #bbb;
      padding: 6px;
      background: white;
      color: #444;
      z-index: 999;
      font-size: 1.25em;
      width: 400px;
      height: 800px;
      overflow: scroll;
    <script type="text/javascript">
      var doStuff = function(){
        var obj = <?php echo $data; ?>;
        var logger = document.getElementById('bsdLogger');
        if (!logger) {
          logger = document.createElement('div');
 = 'bsdLogger';
        var pre = document.createElement('pre');
        var h2 = document.createElement('h2');
        pre.innerHTML = obj;
        h2.innerHTML = '<?php echo addslashes($label); ?>';
      window.addEventListener ("DOMContentLoaded", doStuff, false);

Leave a Reply

Your email address will not be published. Required fields are marked *