开发者

PHP how to remove and add commas

开发者 https://www.devze.com 2023-01-11 08:11 出处:网络
How can I remove extra commas and add commas for example using PHP user submitted data stack,,,,,,,,,,,,,,overflow

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

精彩评论

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