I've just been reading a solved thread with this same title. The solution was nl2br. I was unaware of this function and have been using str_replace instead.
A problem arises however, when converting preformatted text, specifically a table. Either solution leaves a mass of space between text and a table due to all the new lines generated.
Is there a solution to this.