I have a text area that inserts it's content into a SQL table. Is there a way to keep the formatting of the text and then use it in HTML?
+1
A:
Text is text is text. Insert the text into the table including its markup and it will come out that way as well.
...or am I misunderstanding your question?
lc
2010-06-18 13:35:52
I want to keep line breaks. lol
BioXhazard
2010-06-18 13:40:06
@BioXhazard Then you're looking for @rdkleine's or @Pete's answer.
lc
2010-06-18 13:54:41
+2
A:
If you mean keep the Enters then replace the char 10 and char 13 with <br/>
When using SQL (note the enters)
select replace('
test
test','
','<br/>')
This results in <br/>test<br/>test
rdkleine
2010-06-18 13:36:25
Added the SQL code in the answer. What programming language are you using?
rdkleine
2010-06-18 13:42:02
+3
A:
I'll assume you're talking about preserving line breaks.
Either:
Output the text inside a <pre> tag
or
Convert newlines to <br /> tags before insertion to the DB. (E.g. nl2br in PHP).
Pete
2010-06-18 13:39:04
Thank you. The pre tag worked perfectly and allowed me to style the text very easily.
BioXhazard
2010-06-18 13:43:14
Is there a way to get it to paragraph the text? Text seems to keep going on the same line if there are no manual line breaks.
BioXhazard
2010-06-18 13:46:49
You'll need to add extra breaks (word_wrap in PHP) and/or use CSS (set a max width and the overlow attribute)
Pete
2010-06-18 13:49:20
Have you performed some operation to limit the max line length alà word_wrap?Have you used CSS to style the element as suggested (e.g. max-width: 52em; overflow:scroll;) ?
Pete
2010-06-18 14:30:40