Jump to content

Archived

This topic is now archived and is closed to further replies.

ldsmike88

Insert line breaks on key press.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Use PHPs nl2br function instead. Use this when you display the data

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Well if I can do it with PHP does anyone know any good tutorials or have a script to copy and paste? Thanks!

Michael

Share this post


Link to post
Share on other sites
If you want to convert newlines to html line break then use the [url=http://php.net/nl2br]nl2br[/url] function.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.