为什么PHP echo'd文本丢失格式? [英] Why does PHP echo'd text lose its formatting?
本文介绍了为什么PHP echo'd文本丢失格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么想法为什么格式化文本从数据库中,当在php中回声输出失去了格式,即没有新的行?谢谢!
Any ideas why formatted text from DB, when echo-ed out in php loses its formatting, i.e. no new lines? Thanks!
推荐答案
使用 nl2br()
。
新行被浏览器忽略。这就是为什么你看到没有换行符的所有文本。 nl2br()将新行转换为< br />
标签,在浏览器中以新行显示。
New lines are ignored by browser. That's why you see all text without line breaks. nl2br() converts new lines to <br />
tags that are displayed as new lines in browsers.
如果要在< textarea>
,您不需要将所有新行转换为< br />
。无论如何,如果你这样做的话...你会看到< br />
作为新行文本。
If you want to display your text in <textarea>
, you don't need to convert all new lines to <br />
. Anyway, if you do it... you will see "<br />
"s as text in new lines places.
这篇关于为什么PHP echo'd文本丢失格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文