我有这个表单,其中有一个文本区域和一个提交按钮。当您提交它时,它会查询文本区域中的所有内容。
这是这部分代码:
if(isset($_POST['message']))
{
$EscMessage = $iDB->real_escape_string(rip_tags($_POST['message']));
$EscName = $iDB->real_escape_string(rip_tags($_POST['subject'])); // rip_tags just strips HTML
$Today = date("F j, Y, h:i:s A");
$iDB->query("INSERT INTO `Match_Comments` (`URL`, `Name`, `Message`, `Date`) VALUES ('$EscMatch', '$EscName', '$EscMessage', '$Today')");
}
这一切都很好,但是如果我在文本区域中写下注释,例如:
This is the message that I will be writting in the textarea
It includes multiple lines like right now.
And even large blocks of blank spaces.
然后,当我查询数据时,它在 1 行中显示 ^ 该消息,没有空行。我怎样才能解决这个问题?
这就是它的显示方式:(但我希望它就像文本区域中写的那样)
This is the message that I will be writting in the textarea It includes multiple lines like right now. And even large blocks of blank spaces.
以下是我获取数据的方法:
$row['Message'];
最佳答案
html 中的换行符呈现为空格。您应该添加 <br />
有换行符的地方。
使用 nl2br
.
关于php - 在 HTML 中正确格式化多行文本区域字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15057119/