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. Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/ 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 /> Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/#findComment-507778 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. Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/#findComment-507779 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 Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/#findComment-507784 Share on other sites More sharing options...
bradkenyon Posted April 2, 2008 Author Share Posted April 2, 2008 what about paragraph breaks? Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/#findComment-507788 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/#findComment-507828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.