detecting new lines in textarea's using php

I'm sure this has been asked before but I haven't been able to find a solution.  Basically, a user fills out a textarea and they can enter breaks by pressing the Enter key.  How do I use str_replace() to detect the newline characters and replace them with a <br/> so that when it goes into and gets pulled out of the db it will be displayed correctly by the browser?
jpveAsked:
Who is Participating?
 
JimQodeCommented:
nl2br() function does that.

you could also use str_replace("\n","<br>",$string)
0
 
BioICommented:
Hi,
I am usually using this function to change new lines to <br />: nl2br (more information on http://be.php.net/nl2br).

$stringwithbreaks = nl2br($textareastring);

regards,
bioi
0
 
jpveAuthor Commented:
Thanks a ton guys.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.