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
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
Have you turned this into a class that can be used by other developers or something?
I should do that and post it. There’s actually a Pear class available, while I find time to do it with this one.
I gotta fix some stuff up in the iteration too. It’s still messy..
Any help is more than welcome.
Thanks Phillihp
This is great. thanks for releasing it
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
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.
Very useful, thank you very much!!!
Is the Source code for this availible somewhere? Would be awesome
Stefan, I have been slacking. I will get this out at some point. But I want to fix it up a bit first.
Did you ever git this thing up on github or something? I’m sure someone would be willing to branch it and pimp the code
Here you go: https://github.com/phillihpz/PHP-Array-Beautifier
thank u.. its beautiful
very useful, thank you!
I would be great to see collapsible rows!
Works like a charm, thanks
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?
Done. Check out v3.
Thank you! Would you consider making a Chrome extension, or a firefox one? That would be even more awesome
Very useful. Thanks alot!
Thanks! its pretty great and useful!!!
Thanks all your trying! It’s pretty useful and Great!!!
Pretty much good…
Thanks for service. Helps a lot.
Very helpful thanks
Phillip,
Thanks for making this. It saved me alot of time!
Thanks
Bookmarked. This is so useful, thank you.
This is awesome!
Simply beautiful! Thanks a million!
Philip – this is really great, thanks for sharing it. Andy
Thank you for this perfect Tool
Thanks man !
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
Done. Check out v3.
Thanks so much for this, so useful! Bookmarked!
Thank you so much . its works great and still using it ~~ =D
*Cheers*
Pingback: Wicked sick tools to help build and enhance your wesbites
Hi thanks bro, your tools help me
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.
Forgot, Drupal uses # a lot, so I added the following: !#+:
Is it possible to use the old version of your beautifier somewhere? It helped me out a lot
Of-course. I added a link to v2 on the Menu and the top of the v3 page.
It seems to be perfect now, thanks !
Awesome , thanks you
!
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
Why do you have quote’s in your Array keys?? Just playing. I added a stripslashes() on the Key and that seemed to do it.
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 ) )
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.
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.
Thank you, Phillip, it is fantastic helpfull!