I want to replace multiple newline characters with one newline character, and multiple spaces with a single space.
I tried preg_replace(\"/\\n\\n+/\", \"\\n\",
preg_replace(\"/\\n\\n+/\", \"\\n\",
Use \R (which represents any line ending sequence):
$str = preg_replace('#\R+#', '', $str);
', $str);
It was found here: Replacing two new lines with paragraph tags
PHP documentation about Escape sequences:
\R (line break: matches \n, \r and \r\n)