note 46888 deleted from function.print-r by derick
| From: | derick@php.net | Date: | Thu, 27 Oct 2005 10:14:17 +0000 |
| Subject: | note 46888 deleted from function.print-r by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97667@lists.php.net to get a copy of this message | ||
Note Submitter: peranders at peranders dot net
----
These functions will print human-readable information
about a variable in HTML format
Only tested in PHP Version 4.3.1
<?
$person=new stdClass();
$person->name="Jonny";
$person->interests=array('Fishing','Hiking');
echo "<H1>marr (PHP 4 , PHP 5) </H1>";
marr($person);
echo "<H1>marr for all versions 4.3.x above</H1>";
marr_php_version_4_3($person);
function marr($a)
{
ob_start();
print_r($a);
$t= ob_get_contents();
ob_end_clean();
for($c=10;$c>=1;$c--)
{
$search="\n ".str_repeat(" ",4*$c-1);
$replace="<br>\n".str_repeat(" ",8*$c);
$t= str_replace($search,$replace,$t);
}
//Final adjustment which takes care of the single last closing parenthesis
$t= str_replace("\n\n)","<br>\n)",$t);
echo $t;
}
function marr_php_version_4_3($a)
{
$t=print_r($a,true);
for($c=10;$c>0;$c--)
{
$search="\n ".str_repeat(" ",4*$c-1);
$replace="<br>\n".str_repeat(" ",8*$c);
$t= str_replace($search,$replace,$t);
}
//Final adjustment which takes care of the single last closing parenthesis
$t= str_replace("\n\n)","<br>\n)",$t);
echo $t;
}
?>