Fun and exciting regular expression of the day:
<?php $text = preg_replace('/(?:\r\n|\r(?!\n)|(?!<\r)\n){2,}/s', "\n\n", $text); ?>