Boofo
04-25-2011, 08:20 PM
I just found this little snippet of code that works great for replacing print_r when working with code, and thought I would share it here. It prints out like this:
Array
(
[0] => 5
[1] => 6
[2] => 7
)
Here is the code:
if (!function_exists("preprint")) {
function preprint($s, $return=false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) return $x;
else print $x;
}
}
@usage:
preprint($x); <- where $x = array()
NOTE: The optional 2nd parameter can be set to "true", so the html-code is returned.
I haven't quite figured out what the 2nd perimeter actually does as no code has shown up for me when that has been enabled.
Array
(
[0] => 5
[1] => 6
[2] => 7
)
Here is the code:
if (!function_exists("preprint")) {
function preprint($s, $return=false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) return $x;
else print $x;
}
}
@usage:
preprint($x); <- where $x = array()
NOTE: The optional 2nd parameter can be set to "true", so the html-code is returned.
I haven't quite figured out what the 2nd perimeter actually does as no code has shown up for me when that has been enabled.