How can I remove extra commas and add commas for example using PHP

user submitted data


should output.

stack, overflow


When would you add a comma?

Written by Adam Backstrom

@Adam Backstrom add comma example stack, overflow

Written by countDOWN

What's the input, then?

Written by Adam Backstrom

@Adam Backstrom stack,,,,,,,,,,,,,,overflow

Written by countDOWN

Accepted Answer

$out = preg_replace("/,+/",", ",$in);
Written by mvds
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki