tags:

views:

31

answers:

2
A: 

You could do:

$text_of_area = nl2br(str_replace("\r\n", "\n", $_POST['text_area_name']));
Sarfraz
+3  A: 

Why not just replace more than one new line away prior to calling nl2br?

If you want to let them use only one new line at all in their post:

$firstPos = strpos($text, "\n");
if ($firstPos !== false) {
    $text = substr_replace(array("\r","\n"),'', $text, $firstPos + 1);
}
$text = nl2br($text);

If you want to let them use only one consecutive new line (allowing foo\nbar\nbaz):

$text = preg_replace('#[\r\n]+#', "\n", $text);
$text = nl2br($text);
ircmaxell
+1 Exactly what I was going to suggest.
Blizz