You could do:
$text_of_area = nl2br(str_replace("\r\n", "\n", $_POST['text_area_name']));
Sarfraz
2010-07-29 16:51:47
You could do:
$text_of_area = nl2br(str_replace("\r\n", "\n", $_POST['text_area_name']));
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);