Something a bit more functional (easy to use anywhere):
function replace_carriage_return($replace, $string)
{
return str_replace(array("\n\r", "\n", "\r"), $replace, $string);
}
Using PHP_EOL as the search replacement parameter is also a good idea! Kudos.