unknown1 Posted December 15, 2009 Share Posted December 15, 2009 Hello all, I have a script that adds multiple items to a single row in a database table and when I echo it out I get item1, item2, item3,,,,,,,,item14,,,,,item 20 each item represents a radio that was posted to the database in an array.... so the output is comma separated and this is fine but when some of the values are blank it has just the comma e.g. ,,,,,,,,,, is blank posts. Does anyone know of a way I can format this so the output is only one comma after value and if value is empty the extra commas are removed. I have tried str_replace but in that case it replaces all and not just the one NOT needed. Link to comment https://forums.phpfreaks.com/topic/185180-formatting/ Share on other sites More sharing options...
unknown1 Posted December 15, 2009 Author Share Posted December 15, 2009 Any ideas? Link to comment https://forums.phpfreaks.com/topic/185180-formatting/#findComment-977759 Share on other sites More sharing options...
cags Posted December 15, 2009 Share Posted December 15, 2009 Assuming there's nothing between the commas something like this should work... $input = preg_replace('#,+#', ',', $input); Link to comment https://forums.phpfreaks.com/topic/185180-formatting/#findComment-977770 Share on other sites More sharing options...
unknown1 Posted December 15, 2009 Author Share Posted December 15, 2009 ty Link to comment https://forums.phpfreaks.com/topic/185180-formatting/#findComment-977779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.