Keep text formatting in SQL

放肆的年华 提交于 2020-01-03 19:07:08

问题


I have a text area that inserts its content into a SQL table. Is there a way to keep the formatting of the text and then use it in HTML?


回答1:


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




回答2:


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).




回答3:


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?



来源:https://stackoverflow.com/questions/3070033/keep-text-formatting-in-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!