View Full Version : How do I preserve the formating of the text in a HTML textarea while I...
...save it to a file or a database? For eg I want to preserve the line breaks and save it to a file or to a database field
Bert H
10-08-2007, 08:48 PM
Save the file as:
filename.html OR filename.htm
;-)
David D
10-08-2007, 08:48 PM
You don't need to do anything special. The trick is that if you output to a webpage, then extra whitespace will be collapsed. Wrap the content in a pre element, or process it server side to add paragraph and line break elements.
jaxicle
10-08-2007, 08:48 PM
This is as simple as using a separate style sheet for this. Place the selectors and attributes for the textarea you ant in the CSS and it will retain all formatting. Like what was said before, you don't need to worry about line breaks.
kaos713
10-09-2007, 04:53 AM
Copying and pasting should still preserve that simple formatting, line breaks are characters, and will be copied.
Robert H
10-09-2007, 04:59 AM
Well, I'm assuming you're using some sort of server-side script, like PHP or PERL. What you might want to do is search the inputted data from the textarea for escape characters such as:
-'\n' : newline
-'\t' : tab
And process these accordingly using the scripting language of your choice. Let me know if this works for you or not.
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.