ldsmike88 Posted October 3, 2006 Share Posted October 3, 2006 I have several forms on my websites where the user can type in information, click submit, and it shows up somewhere on the website. The only problem is most of the people entering information don't have a clue how to write HTML. What I want to do is when the user presses submit I want to convert all the times they pressed enter into line break tags (br /). Does anyone know how to do this or have a really good tutorial I can use? Thanks!!Michael Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/ Share on other sites More sharing options...
fenway Posted October 3, 2006 Share Posted October 3, 2006 While you could do this in JS with a simple .replace() call onblur, or something equivalent, I would recommend that you do this on the server-side script. Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-103384 Share on other sites More sharing options...
wildteen88 Posted October 4, 2006 Share Posted October 4, 2006 Use PHPs nl2br function instead. Use this when you display the data Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-103625 Share on other sites More sharing options...
fenway Posted October 4, 2006 Share Posted October 4, 2006 It really depends what you're using it for... if you're _always_ going to be converting it, you might as well store it that way. However, storing formatting in the DB is lazy and bad -- it's usually better to keep it pristine. Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-103909 Share on other sites More sharing options...
ldsmike88 Posted October 5, 2006 Author Share Posted October 5, 2006 Well if I can do it with PHP does anyone know any good tutorials or have a script to copy and paste? Thanks!Michael Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-104064 Share on other sites More sharing options...
wildteen88 Posted October 5, 2006 Share Posted October 5, 2006 If you want to convert newlines to html line break then use the [url=http://php.net/nl2br]nl2br[/url] function. Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-104323 Share on other sites More sharing options...
ldsmike88 Posted October 5, 2006 Author Share Posted October 5, 2006 That nl2br works great. Thanks!Michael Quote Link to comment https://forums.phpfreaks.com/topic/22893-insert-line-breaks-on-key-press/#findComment-104457 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.