Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:21:54+00:00 2026-06-12T04:21:54+00:00

Doing print_r , returns pages and pages of code; it’s too hard to scroll

  • 0

Doing print_r, returns pages and pages of code; it’s too hard to scroll pages to match children to parents, even wrapped with <pre> tags.

Is there a way to theme print_r into collapsible fields. Maybe an online generator, where I can post the contents of the print_r($array); and get a collapsible table of fields.

For example, in Drupal, there’s a module, called Devel, that does just that.
Devel Screenshot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:21:55+00:00Added an answer on June 12, 2026 at 4:21 am

    Thanks to this post, here’s a solution.

    Insert the following function, right before the print_r.

    <?php
    function print_r_tree($data)
    {
        // capture the output of print_r
        $out = print_r($data, true);
    
        // 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(\''.(\$id = substr(md5(rand().'\\0'), 0, 7)).'\');\">\\2</a><div id=\"'.\$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);
    
        // 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";
    }
    ?>
    

    And then, substitute print_r(), with print_r_tree(); like this:

    <pre><?php echo print_r_tree(get_defined_vars()); ?></pre>
    

    Don’t forget the <pre> tags.

    The results look identical to that of print_r() function, except that now the arrays are collapsible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE 4: print_r( $data ); returns the data I posted in the original question,
I am having a problem with my code. What it seems to be doing
I am doing this at the moment <?php $xml = simplexml_load_file('www.tompeters.com/atom.xml'); print_r($xml); ?> but
We are doing an app to manage and print Word, Excel, PowerPoint, and PDF
So I have been doing some research into getting my UTF8 to print correctly.
I'm doing some random experimentation and want to print out the address the program
What am I doing wrong? I expected the Java program to print private. My
Ok, so I can print a PDF doing: pdf2ps file.pdf - | lp -s
Can you please suggest to me the syntax for doing floating point comparison in
Can anyone please point out what im doing wrong with this Stored Procedure please.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.