<?php

$text = <<<STR
First  sentence
Second sentence
Third    sentence
STR;
print($text."\n\n");

$text = preg_replace( '/ +/', ' ', $text );
print($text."\n\n");

$text = str_replace( array( "\r", "\r\n", "\n"), '  ', $text );
print($text."\n\n");

$text = str_replace( '  ', "\n", $text );
print($text."\n\n");