开发者

PHP how to remove and add commas

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜