kieranbarnes Independent PHP, WordPress & CubeCart Programmer

Nice print_r() for the web

Posted on July 18, 2007

Here's a nicer version of the print_r() function that displays much better on web pages.

function dump($in) {
ob_start();
$out= "<pre>";
print_r($in);
$out.= ob_get_contents();
ob_end_clean();
$out.= "</pre>";
return $out;
}

Usage:

echo $out;

It should print something that is actually readable, as opposed to the built in print_r() function that provides no line breaks in a browser.


Related posts

  1. I heart MDB2
    I recently started a project for a customer, if it's CubeCart, WordPress or BackPress based,...
  2. What is the difference between ‘learnt’ and ‘learned’?
    Apparently, not much. These are alternative forms of the past tense and past participle of...
  3. Insert Coin
    Bored at work? This script connects to a JetDirect equipped HP printer and uses HP's...
  4. Yahoo GeoLocation API
    The Yahoo Maps API is the best API I've found for using on in internal...
  5. ADOdb’s GetMenu() function moreAttr bug
    I'm sure there is a bug with ADOdb's GetMenu() function The documentation suggests 'use $moreAttr...

Filed under: PHP Leave a comment
Comments (1) Trackbacks (0)
  1. For the record, passing true as the second param to print_r will return the value and not display. ie, your function can be simplified as so;

    function dump($in) {
    $out= “”;
    $out .= print_r($in, true);
    $out.= “”;
    return $out;
    }


Leave a comment

(required)

No trackbacks yet.