PHP Array Beautifier

Version 3.2

This simple tool takes an array or object output in PHP, such as a print_r() statement and formats it to be easily readable. A new feature includes the ability to expand and contract the array to make things more manageable. In addition, if you would like to re-use the array, you can unserialize the object's serialized string, also exported.
New Fixes (2015.07.10):
  • Added strip slashes to keys
New Fixes (2015.06.11):
  • Escaping Quotes
  • Print in Text format
  • Array Keys can now use 'a' to 'Z' characters, '0' to '9', and '_', '-', ' ', '!', '#', '+', ':'
    Thanks for the find Maarlock

Code to Transform:


Change Log:

v3.1

  • Escaping Quotes
  • Print in Text Format
  • Array Keys can now use 'a' to 'Z' characters, '0' to '9', and '_', '-', ' ', '!', '#', '+', ':' - Found by Maarlock
  • Rebuilt into Data Model
  • Convert to Object Script
  • Clean Print of Data after Object Encoding
  • Expand and Collapse
  • Serialized Object
  • Route Display

v2

  • Corrections for bad Data
  • Color Coding
  • Example Dump Code

v1

  • Simple Tabbing Export

52 Responses to PHP Array Beautifier

  1. Have you turned this into a class that can be used by other developers or something?

  2. vivek says:

    Thanks Phillihp :)

  3. Rob says:

    This is great. thanks for releasing it

    • Binod says:

      Pretty awesome code, I’ve been klioong to add this to my personal blog, but this will do much better than a plugin =D@Minnesota Attorney, no the code does all the work really, it’s not a built in thing to wordpress.Till then,Jean

  4. Josh Anderson says:

    I broke the array beautifier with some array that I entered into it,

    • Known Issues with v1 and v2: Extra added parenthesis
      v3 accounts for most of these using Regex searches instead of simple iterative character searches.
      Note, there are still off-cases that can break it. The nature of the print_r format.

  5. Luca says:

    Very useful, thank you very much!!!

  6. Stefan says:

    Is the Source code for this availible somewhere? Would be awesome :D

  7. sharath says:

    thank u.. its beautiful

  8. genevieve says:

    very useful, thank you!

  9. Timofey says:

    I would be great to see collapsible rows!

  10. toufik_at says:

    Works like a charm, thanks

  11. Kimberly says:

    Works well! It is not obvious, thugoh. Will new users know to click on the yellow bubble or time stamp?Within the thread itself, perhaps you can put the same yellow bubble next to the title of the thread to keep things consistent? Maybe a yellow bubble with a down arrow?

  12. Jimmy Arogen says:

    Thank you! Would you consider making a Chrome extension, or a firefox one? That would be even more awesome :)

  13. Very useful. Thanks alot!

  14. Won JeonHwan says:

    Thanks! its pretty great and useful!!!

  15. Won JeonHwan says:

    Thanks all your trying! It’s pretty useful and Great!!!

  16. SkY2kv says:

    Pretty much good…

  17. Damir says:

    Thanks for service. Helps a lot.

  18. Zain Saqer says:

    Very helpful thanks

  19. Nick Julia says:

    Phillip,

    Thanks for making this. It saved me alot of time!

    Thanks

  20. Caedmon says:

    Bookmarked. This is so useful, thank you.

  21. Luka Kraljevic says:

    This is awesome!

  22. drrk says:

    Simply beautiful! Thanks a million!

  23. AndyG says:

    Philip – this is really great, thanks for sharing it. Andy

  24. Thank you for this perfect Tool

  25. Bart says:

    Wow man I’ve been using this for quite a while now and it saved me sooo much time.
    Thanks a lot, really appreciated!

    Maybe an extra useful feature, especially for large multidimensional arrays:
    The possibility to expand and contract each array (with a minus and plus icon in front of each array).
    This way you have a lot more overview and you need to scroll less.

    Regards,
    Bart

  26. Thanks so much for this, so useful! Bookmarked!

  27. Yuki AY says:

    Thank you so much . its works great and still using it ~~ =D

    *Cheers*

  28. Pingback: Wicked sick tools to help build and enhance your wesbites

  29. Rifqi says:

    Hi thanks bro, your tools help me ;)

  30. Maarlock says:

    Hi man, thanks a lot for this tool, I’m using it all the time !
    However since you updated it I have a problem :

    If I try to beautify an array with number as indexes like this :
    Array ( [0] => this [1] => is [2] => Array ( [0] => a [1] => test ) )
    it doesn’t work.

    But if I replace numbers by letters, there is no problem, the beautified array is perfect :
    Array ( [a] => this [b] => is [c] => Array ( [d] => a [e] => test ) )

    Is it me doing it wrong or do you have a problem ?

    • Great Catch! That was an issue on my end. The new code searches for regular expressions. Apparently, I only had, lowercase a to z and uppercase A to Z.

      \[{1}[a-zA-Z]*\]{1}\s{1}\={1}\>{1}\s{1}Array\s*\n*\s*\({1}

      I went ahead and added digits, underscores, dashes, and spaces (although that is bad practice, I’ve seen it done.

      \[{1}[a-zA-Z0-9-_\s]*\]{1}\s{1}\={1}\>{1}\s{1}Array\s*\n*\s*\({1}

      Give it another try. let me know if that fixes it for you.

  31. Ken says:

    Is it possible to use the old version of your beautifier somewhere? It helped me out a lot :)

  32. Maarlock says:

    It seems to be perfect now, thanks ! :-)

  33. Ken says:

    Awesome , thanks you :) !

  34. Giomar MG says:

    I think there’s a problem when I have an array with quotation marks in the v3, for example if I have a key [ABC's] => Array (Content)
    It will read it as [ABC/'s] => “Array (” [Content]
    v2 works fine with that, thanks

  35. munafar says:

    try this array example… not show all… but it works on v2…

    Array ( [0] => Array ( [Enterprise] => Array ( [Large Corp & Region] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH [9] => II [10] => JJ [11] => KK [12] => LL [13] => MM [14] => NN ) [Hospitality and Logistic] => Array ([0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH [9] => II [10] => JJ ) [Services] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH [9] => II [10] => JJ [11] => KK [12] => LL ) [Bank] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH ) [Financial Services] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF ) [Education & GLC] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH [9] => II ) [Government] => Array ( [0] => [1] => AA [2] => BB [3] => CC [4] => DD [5] => EE [6] => FF [7] => GG [8] => HH [9] => II ) ) ) [1] => Array ( [1] => Large Corp & Region [2] => Hospitality and Logistic [3] => Services [4] => Bank [5] => Financial Services [6] => Education & GLC [7] => Government ) )

  36. Diego says:

    It seems there is a problem when an element has an empty value, the parsing just breaks. It was working (and still is) in the v2.

    Here is an example:
    Array ( [id] => 2790 [another_field] => )

    The “another_field” is empty. This is the way it’s generated by the “print_r()” function of PHP.

  37. Hi, if I try to beautify an array with an empty property like Array( [a] => ’0′, [b] => ,[c]=>’2′ ) then the beautifier stop at the empty one ignoring every other properties at the same level.

  38. Clone says:

    Thank you, Phillip, it is fantastic helpfull!

Leave a Reply to Jeremy_FP Cancel reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>