php regex: removing more than double space

后端 未结 2 419
长发绾君心
长发绾君心 2021-01-23 15:26
$tags = preg_replace(\'/\\s\\s+/\',\' \', $tags);

that will remove more than just one space ?

i need to remove anything more than double space.

2条回答
  •  一向
    一向 (楼主)
    2021-01-23 15:38

    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.

提交回复
热议问题