note 101593 added to function.print-r
| From: | lsiqatpapotamcom at osu1 dot php dot net | Date: | Tue, 28 Dec 2010 18:28:01 +0000 |
| Subject: | note 101593 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175284@lists.php.net to get a copy of this message | ||
// some little fixes to Bob's great function
// (perfomance, and null key)
// thanks Bob, it is realy lovely.
<?php
function print_r_tree($data)
{
// capture the output of print_r
$out = print_r($data, true);
$cid = 1;
// fixes "[] =>" (null key)
$out = preg_replace("/\[]\s+=>/", "[this text is not a key, do you have a key
like this] =>", $out);
// replace something like '[element] => <newline> (' with <a
href="javascript:toggleDisplay('...');">...</a><div
id="..." style="display: none;">
$out = preg_replace('/([ \t]*)(\[[^\]]+\][ \t]*\=\>[ \t]*[a-z0-9 \t_]+)\n[
\t]*\(/iUe',"'\\1<a href=\"javascript:toggleDisplay(\'x'.(\$id =
\$cid++).'\');\">\\2</a><div id=\"x'.\$id.'\"
style=\"display: none;\">'", $out);
// replace ')' on its own on a new line (surrounded by whitespace is ok) with
'</div>
$out = preg_replace('/^\s*\)\s*$/m', '</div>', $out);
$out = str_replace("[this text is not a key, do you have a key like this] =>",
"[] =>", $out);
// print the javascript function toggleDisplay() and then the transformed output
echo '<script language="Javascript">function toggleDisplay(id) {
document.getElementById(id).style.display = (document.getElementById(id).style.display ==
"block") ? "none" : "block";
}</script>'."\n$out";
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 190.225.76.226
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- https://master.php.net/note/edit/101593
Del: integrated -- https://master.php.net/note/delete/101593/integrated
Del: useless -- https://master.php.net/note/delete/101593/useless
Del: bad code -- https://master.php.net/note/delete/101593/bad+code
Del: spam -- https://master.php.net/note/delete/101593/spam
Del: non-english -- https://master.php.net/note/delete/101593/non-english
Del: in docs -- https://master.php.net/note/delete/101593/in+docs
Del: other reasons-- https://master.php.net/note/delete/101593
Reject -- https://master.php.net/note/reject/101593
Search -- https://master.php.net/manage/user-notes.php