Try
$nl_char = "\n"; // change to your needs
$str = preg_replace("/[\r\n]+/", $nl_char, $str);
This should match consecutive linebreaks of win, *nix and mac style, replacing them with 1 linebreak of the desired style (I think it actually should not hurt to have the linebreak style consistent after this modification, but maybe that is still not exactly what you want).