Jump to content

Trim array print_r?


EchoFool

Recommended Posts

Hey

 

 

Is there a way to trim the print_r($array); so its completed and void of white space?

 

 

It prints like this:

 

 

 


Array
(
    [0] => Array
        (
            [id] => 10
            [f] => data/tiles/image.png
        )
)

 

 

But I want it to be compressed like this:

 

 

Array([0]=>Array([id]=>10[f]=>data/tiles/image.png))

This is then to be stored in the database, so any compressed possible is a plus in this situation.

 

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/257511-trim-array-print_r/
Share on other sites

You can do a regex replace of white-space.  Though that'd remove it from any string values if you have them.

$out = print_r($arr, true);
$out = preg_replace('/\s+/', '', $out);

 

edit:

why are you storing the output of print_r in a database?

Link to comment
https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319848
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.