tags:

views:

37

answers:

3

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
I want to keep line breaks. lol
BioXhazard
@BioXhazard Then you're looking for @rdkleine's or @Pete's answer.
lc
+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
How could I do that?
BioXhazard
Added the SQL code in the answer. What programming language are you using?
rdkleine
where does this code go exactly? And I'm using VB.
BioXhazard
In your select query.
rdkleine
Or in VB >> textbox.Text = Value.Replace(vbCrLf, "<br/>")
rdkleine
What is value supposed to be?
BioXhazard
Nevermind, it works. Thanks!
BioXhazard
No problem :D good luck
rdkleine
+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
Thank you. The pre tag worked perfectly and allowed me to style the text very easily.
BioXhazard
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
You'll need to add extra breaks (word_wrap in PHP) and/or use CSS (set a max width and the overlow attribute)
Pete
Set overflow to what exactly?
BioXhazard
The text is still going outside the layout.
BioXhazard
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