Here's a function to replace linebreaks to html <p> tags. This was initially designed to receive a typed text by a form in a "insert new notice" page and put in a database, then a "notice" page could get the text preformatted with paragraph tags instead of linebreaks that won't appear on browser. The function also removes repeated linebreaks the user may have typed in the form.
function break_to_tags(&$text) {
// find and remove repeated linebreaks
$double_break = array("\r\n\r\n" => "\r\n");
do {
$text = strtr($text, $double_break);
$position = strpos($text, "\r\n\r\n");
} while ($position !== false);
// find and replace remanescent linebreaks by <p> tags
$change = array("\r\n" => "<p>");
$text = strtr($text, $change);
}
[]'s
Fernando