For some reasons I don't know, when I display $text, I still have \n and \n\n on screen. I addslashes when inserting to database and stripslashes $text before the statements below, then displaying it. What's wrong with ereg_replace?
// Strip out carriage returns
$text = ereg_replace("\r","",$text);
// Handle paragraphs
$text = ereg_replace("\n\n","<P>",$text);
// Handle line breaks
$joketext = ereg_replace("\n","<BR>",$text);