开发者

Regular expressions to remove space and whitespace in PHP?

I'm looking for regular expressions to remove space and whitespace 开发者_JAVA百科before and after a comma.


Try this:

$output = preg_replace('/\s*,\s*/', ',', $str);

This will replace all commas with possible leading and trailing whitespace characters (\s) by a single comma.


preg_replace('/\s*,\s*/', ',', $target_string);


You don't need regex for this.

$output = explode(',', $input);
$output = array_map('trim', $output);
$output = implode(',', $output);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜