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