Skip to content

Instantly share code, notes, and snippets.

@accentinteractive
Created October 5, 2012 07:09
Show Gist options
  • Save accentinteractive/3838495 to your computer and use it in GitHub Desktop.
Save accentinteractive/3838495 to your computer and use it in GitHub Desktop.

Revisions

  1. @joostvanveen joostvanveen revised this gist Oct 5, 2012. No changes.
  2. @joostvanveen joostvanveen revised this gist Oct 5, 2012. No changes.
  3. @joostvanveen joostvanveen revised this gist Oct 5, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions dump_helper.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    <?php
    /**
    * Dump helper. Functions to dump variables to the screen, in a nicley formatted manner.
    * @author Joost van Veen
    * @version 1.0
    */
    if (!function_exists('dump')) {
    function dump ($var, $label = 'Dump', $echo = TRUE)
    {
  4. @joostvanveen joostvanveen created this gist Oct 5, 2012.
    29 changes: 29 additions & 0 deletions dump_helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    if (!function_exists('dump')) {
    function dump ($var, $label = 'Dump', $echo = TRUE)
    {
    // Store dump in variable
    ob_start();
    var_dump($var);
    $output = ob_get_clean();

    // Add formatting
    $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
    $output = '<pre style="background: #FFFEEF; color: #000; border: 1px dotted #000; padding: 10px; margin: 10px 0; text-align: left;">' . $label . ' => ' . $output . '</pre>';

    // Output
    if ($echo == TRUE) {
    echo $output;
    }
    else {
    return $output;
    }
    }
    }


    if (!function_exists('dump_exit')) {
    function dump_exit($var, $label = 'Dump', $echo = TRUE) {
    dump ($var, $label, $echo);
    exit;
    }
    }