first thing that comes to my mind are regular expression.
let's see, linebreaks may either be \r\n or \r or \n depending on OS. if it is predictable for you which one will it be, things should be easier, but this catches all 3:
$content=preg_replace('/(\r\n|[\r\n]){3,}/', "$1$1", $content);
but it would not work if there are tabs or spaces on the "blank" lines, so you might prefer:
$content=preg_replace('/((\r\n|[\r\n])(\s| )*?){3,}/', "$2$2", $content);
this is just one way, there may be others, maybe easier than this and I just didn't think of it.