How do I get the nl2br function to format the text as follows:
This is one line<br><br>This is another line
This is one line
<br><br>
This is another line
The input source of this text is a web form textbox.
nl2br() only replaces newlines by break-tags, so the layout should already by as you want it.
try using echo htmlspecialchars($string);
to see if there are any other characters like "\r" that may be messing up the layout.
So does that mean that when I convert the following...
This is the first line\n \n This is the second line
It will convert it to:
This is the first line<br><br>This is the second line
(with no new lines?)
From the manual:
"Returns string with '<br />' inserted before all newlines."
INSERTED BEFORE not replaced with.
To replace them, use ereg_replace("\n", "<br>",...)
Thanks
Even better would be to use str_replace("\n","<br>",...); since you are not dealing with regular expressions.