EchoFool Posted February 22, 2012 Share Posted February 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/ Share on other sites More sharing options...
kicken Posted February 22, 2012 Share Posted February 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319848 Share on other sites More sharing options...
EchoFool Posted February 22, 2012 Author Share Posted February 22, 2012 Yeh its fine if it removes them from strings! Thanks for the info! : ) Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319849 Share on other sites More sharing options...
Pikachu2000 Posted February 22, 2012 Share Posted February 22, 2012 May I ask why you'd store that in a database, instead of just storing it serialized? Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319850 Share on other sites More sharing options...
EchoFool Posted February 22, 2012 Author Share Posted February 22, 2012 Well i store it as an array then load it then json_encode it for javascript. I've not heard of serialized before? Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319851 Share on other sites More sharing options...
kicken Posted February 22, 2012 Share Posted February 22, 2012 PHP has serialize and unserialize functions that will convert variables to/from string form. In your case though, why not just json_encode the array and store that in the database? Quote Link to comment https://forums.phpfreaks.com/topic/257511-trim-array-print_r/#findComment-1319856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.