Replace multiple newlines, tabs, and spaces

Viewed 84925

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", $text); and failed!

I also do this job on the $text for formatting.

$text = wordwrap($text, 120, '<br/>', true);
$text = nl2br($text);

$text is a large text taken from user for BLOG, and for a better formatting I use wordwrap.

10 Answers
Related