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\",
I would suggest something like this:
preg_replace("/(\R){2,}/", "$1", $str);
This will take care of all the Unicode newline characters.