bradkenyon Posted April 2, 2008 Share Posted April 2, 2008 got a question, say you have a textarea, and you put content in there and throw it into a db table, then display it on webpage, if the user hits enter to put a line break in the textarea box of the form, how do i tell it to put it into the db as a line break, and display it on the webpage as a line break. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted April 2, 2008 Share Posted April 2, 2008 break line such as \n\r or a html break line <br /> Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted April 2, 2008 Author Share Posted April 2, 2008 i am making a quick content management system and i want to allow the user to press enter within the text field (textarea) and it will create a line break, like you would in any typical word processor. So it will display the content they typed into the field as w/ the line break from when they pressed enter. i hope i didn't make it too confusing. Quote Link to comment Share on other sites More sharing options...
quickstopman Posted April 2, 2008 Share Posted April 2, 2008 this always worked for me for line breaks!!! function line_break($str) { str_replace(" ", "<br>", $str); echo $str; } hope that works for ya so to implement it make $textarea line_break($textarea); -Zack Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted April 2, 2008 Author Share Posted April 2, 2008 what about paragraph breaks? Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 2, 2008 Share Posted April 2, 2008 nl2br is your best best for this. If you want paragraph breaks as well, trying using regex <?php $regex = array ( '/(\\r\\n\\r\\n|\\n\\n)/', '/(\\r\\n|\\n)(?!\\r\\n|\\n)/', '/_NL_/' ); $replace = array ( "</p>_NL_<p>", "<br />_NL_", "\n" ); $subject = 'This is a new line This is a new paragraph Another paragraph'; $result = preg_replace($regex, $replace, $subject); echo "<p>$result</p>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.