Why does PHP echo#39;d text lose its formatting?(为什么 PHP 回显的文本会丢失其格式?)
问题描述
任何想法为什么来自 DB 的格式化文本,当在 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 回显的文本会丢失其格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 PHP 回显的文本会丢失其格式?


基础教程推荐
- Web 服务器如何处理请求? 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01