How can I remove extra commas and add commas for example using PHP
user submitted data
stack,,,,,,,,,,,,,,overflow
should output.
stack, overflow
$out = preg_replace("/,+/",", ",$in);
$str = preg_replace('/,+/' , ',' , $str);
This will replace each sequence of one or more commas with one comma.
preg_replace('/[,]+/', ',', $string);
should do it... though depending on the nature of the input you may need a more complex expression.