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



March 18th, 2011 - 10:16
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;
}