开发者

php regex: removing more than double space

开发者 https://www.devze.com 2022-12-20 04:11 出处:网络
$tags = preg_replace(\'/\\s\\s+/\',\' \', $tags); that will remove more than just one space ? i need开发者_StackOverflow社区 to remove anything more than double space.I\'m taking \"more than double
$tags = preg_replace('/\s\s+/',' ', $tags);

that will remove more than just one space ?

i need开发者_StackOverflow社区 to remove anything more than double space.


I'm taking "more than double space" to mean 3 or more spaces:

$tags = preg_replace('/\s{3,}/',' ', $tags);

This will replace 3 or more contiguous occurrences of any whitespace character with a single space.


So you want to replace a sequence of 2 or more spaces with a single space? What you've got there is pretty much it, except that it will match any whitespace (tabs, etc) not just spaces.

0

精彩评论

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