note 45002 added to function.print-r
| From: | oracle dot shinoda at gmail dot com | Date: | Mon, 23 Aug 2004 05:43:44 +0000 |
| Subject: | note 45002 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75141@lists.php.net to get a copy of this message | ||
I noticed that a lot of the examples below seem to make heavy use of recursion and other fancy
features, without going for the easy solution. There's no need to use recursion, when print_r()
already does 99% of the job! Here is my version of print_r(), with HTML entities escaped and the
same format as the normal print_r().
<?php
/**
* printr
* ------
* Function to produce the output of print_r() but in HTML
* form.
*/
function printr ( $var, $do_not_echo = false )
{
ob_start();
print_r($var);
$code = htmlentities(ob_get_contents());
ob_clean();
if ( !$do_not_echo )
{
echo "<pre>$code</pre>";
}
return $code;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45002
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45002&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45002&report=yes
Search -- http://master.php.net/manage/user-notes.php