Reputation: 13943
I am storing a text in a SQL server database as a varchar(MAX)
.
I have to display this text in my web page.
The problem is that the text contains line break.
When I go in the HTML source code, I can see the line breaks but it does not display them in the web page.
Thanks for your help!
Upvotes: 1
Views: 9741
Reputation: 11
There is one way around this without manipulating your SQL. Use a paragraph tag WITHIN a pre tag like so...
<pre><p>Your SQL Would Go Here</p></pre>
You can then use some CSS for your pre tag to wrap the text...
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
Upvotes: 1
Reputation: 130
instead of storing line break in database, store the HTML content with all the formatting and
tags.
Upvotes: 0
Reputation: 93161
Line breaks are ignored in HTML at the display level. Replace these linebreaks with <br/>
tags:
SELECT REPLACE(column_name, CHAR(13) + CHAR(10), '<br/>')
FROM table_name
Upvotes: 1