Php 如何在mysql记录中包含换行符?

Php 如何在mysql记录中包含换行符?,php,mysql,formatting,Php,Mysql,Formatting,当有人键入要放入数据库的以下内容时: Hello, My name is John and I am 22, and looking for a good time. My Phone Number is: 555-NOT-REAL Sincerely, John D. <?php $string= "this is a string"; echo $string. "<br />"; echo nl2br($string); ?> 我希望折线保持在那里,但

当有人键入要放入数据库的以下内容时:

Hello,

My name is John and I am 22, and looking for a good time.

My Phone Number is:
555-NOT-REAL

Sincerely,
John D.
<?php
$string= "this
is
a
string";

echo $string. "<br />";

echo nl2br($string);
?>
我希望折线保持在那里,但当我把值拉回来时,结果如下

Hello, My name is John and I am 22, and looking for a good time. My Phone Number is: 555-NOT-REAL Sincerely,John D.
是否有一种特殊的字段保存输入的文本格式?我非常确定它已经在那里了,因为当我查看数据库中的字段时,特征线确实出现了。也许这就是我找回它的方式


我更喜欢不用编写代码来放入HTML标签,哈哈。谢谢

如果我没记错(我玩MySQL已经有一段时间了),您应该用转义序列替换换行符\n

如果您在浏览器中显示文本,则必须在其中添加HTML标记。浏览器不会自动为您放置换行符。这是最常用的功能:

nl2br($message);
但是,您也可以将文本环绕在标记周围,但我不建议这样做:

$message

读取:

您使用哪种类型的字段来键入数据?关键是要使用文本区域来理解你。从DB获取数据后,将“\n”替换为“
”。
<?php
$string= "this
is
a
string";

echo $string. "<br />";

echo nl2br($string);
?>
this is a string
this
is
a
string