php - 来自 textarea 和 mysql 的换行符不会出现在 html 中

标签 php html mysql textarea line-breaks

如何让文本出现在 html 中的差异行上?!当从 mysql 输出时,它们出现在我的文本区域的 diff 行上,也出现在 mysql 内部的 diff 行上。但是在网页中,它全部在一条线上。如何解决?

enter image description here

最佳答案

使用:

string nl2br ( string $string [, bool $is_xhtml = true ] )

它可以处理\n , \r , \r\n\n\r换行符并用 <br /> 替换它们

例子:

$yourText = "This is line one.\nThis is line two.";
$yourText = nl2br($yourText);
echo $yourText;

这将导致:

This is line one.<br />This is line two.

Link to the manual for more information.

关于php - 来自 textarea 和 mysql 的换行符不会出现在 html 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13861877/

相关文章:

php - 使用 jQuery 或 PHP 编辑 &lt;title&gt; 标签

html - 即使窗口大小发生变化,如何使文本垂直对齐

jquery - 带有 float :left and Form with Bootstrap 的菜单

php - 对第三个关系表中的数量求和

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - 当文件尚不存在时防止类似 LFI 的漏洞

html - Angular 7 - 如何设置 Material 菜单的样式以使元素彼此靠近

mysql - 选择一个表正在关闭我的 MySQL 服务器(错误 2013)

mysql - 用于 Mysql 的 Ole 数据库连接器

PHP system() 函数 - 它是否使用 shell 来执行命令?