$text = "line \n\n\n\n\n\n\n\nline\nline"; $text = preg_replace("/([\n\n]+)/", "\n", $text); echo '<pre>', $text;