将除换行符外的所有多空格字符替换为单个空格


Replace all multispace characters with a single space EXCEPT the newline character

标题不言自明。

目前我使用preg_replace('/'s+/', ' ',$row['message']);,但这也删除了换行符,但我想保留它们。

使用双反类,并对'n取反。这是使用正则表达式否定的完美情况!

preg_replace('/[^'S'n]+/', ' ', $row['message']);

这是一个regex演示。