【发布时间】:2017-03-29 09:17:42
【问题描述】:
当有多个空格时,如何用  替换除第一个(空白)之外的所有空格?
特别要求与php的preg_replace一起使用,所以PCRE。
"This is my text."
应该转换成
"This is my text."
【问题讨论】:
-
试试
preg_replace("!\s+!", " ", $text);。可以举个例子吗? -
也许,你想要
preg_replace("!\s{2,}!", " ", $text); -
@WiktorStribiżew 上面提供的示例。
-
这是一个有趣的问题。我无法用
\G实现它。但我认为您可以只使用preg_replace('~(?<=\s)\s~', '&nbsp;', $s)- 请参阅this demo。