Handling strings in any way shape or form? Crack open the regex function ([man]ereg/man and [man]ereg_replace/man). You can abuse strings in way way imagineable. For example, take you imploded string, $str, and convert multiple newlines to a single newline:
$str = implode($stuff);
$str = ereg_replace("(\n|\n\r){2,}", "\\1", $str);
Having not used this myself, I do not know if this works. Please test it and tell me if I boloxed it. Hopefully you are at least looking in the right direction for you solution now 😛
Uh, the second argument to ereg_replace() should have two whacks (\ twice) before the '1'... PHP won't display it though.