...

View Full Version : textarea basic formatting?



the moose
10-20-2009, 05:22 PM
I've got an HTML textarea that is the input for a large bit of text.

Sometimes, the user will hit return on their keyboard and this will of course drop the text after onto the line below.

The problem I'm having is that I want it to display like it is entered when it is output from the database, but I have no idea how to do this without using an javascript based WYSIWYG HTML editor which I don't want to do as it is massive overkill for what I want to do.

Any ideas?

Cheers

The Moose

abduraooft
10-20-2009, 06:07 PM
http://php.net/nl2br

the moose
10-20-2009, 06:18 PM
http://php.net/nl2br

Thank you!!

Is there a reverse? i.e. br2nl?? (i.e. when editing the text in another textarea)

Cheers

The Moose

SKDevelopment
10-20-2009, 06:36 PM
Please notice that nl2br() does not replace line end characters with <br />. It just adds <br /> after line end characters.

It is better not to store the text to the database with <br />. You only apply nl2br() to the text extracted from the DB when you output the text in HTML context.

If you do not store <br /> or any other HTML formatting to the database you could show and edit the text in as many textarea fields as you need. You simply would not need and reverse function for nl2br().

There is no standard reverse PHP function for nl2br(). You could easily write it e.g. using str_replace() (http://php.net/str_replace) but I do not see where you could possibly need it ...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum