Stop Censorship Stop Censorship Ribbon  Formatting print_r(); to be readable | A Blog about Web Design & Development. WordPress development. Tutorials

Formatting print_r(); to be readable Published on May 26, 2010

Reduzir tamanho de letra Aumentar tamanho de letra Impressão optimizada do artigo Enviar por email
User friendly array listings, by formatting print_r();

When you wish to see the contents of any PHP array, typically you use the print_r() function.

This will print all the array contents in a very messy text block, without any line-breaks whatsoever, wich is quite difficult to read and browse trough.

Wouldn’t it be so much nicer to show the array contents split by line, clean and easy to read and browse., to find what you’re looking after? This is what we will do in this post.

Simply copy and paste this chunk of code in to any .php file:

<?php function print_r_neat($arr) {
?>

<?php print_r($arr); ?>

<?php
} ?>

Now all you have to do is call the function and pass on it the desired array.

Like this:
<?php print_r_neat($YourArray); ?>

For instance:
<?php print_r_neat($_SERVER);?>

And you’ll end up with a nice user friendly array listing!

Have fun!

One Comment on “Formatting print_r(); to be readable”

  1. dXm99 says:

    Have You tried var_dump instead. It will format Your objects/arrays with both line breaks, indent and coloring.

Go ahead! Leave your comment on this subject!

Fields marked with (*) are mandatory!

Spam Protection by WP-SpamFree

Resources
Goodies & Infos
Earn money with your photos

Tip: go to Shutterstock, submit your photos and make an extra income every month. - I do!

MAC

 

Categories

 

External Resources
Twitter Updates
    © 2010 - All rights reserved - WDMAC A Blog about Web Design & Development. WordPress development. Tutorials