【发布时间】:2016-02-14 09:53:25
【问题描述】:
我创建了一个简单的墙贴功能,例如在 Facebook 上。
用户写了一个帖子,帖子被提交到数据库,然后回显到网站上;一切正常。
唯一的问题是,当文本回显到网站上时,换行符不是。所以,我输入:
“嘿,这是一个帖子。
这是一个新的段落”
它显示为:
“嘿,这是一篇文章。这是一个新段落”
我在这里看到一些帖子说要使用 nl2br() 函数并输入 /n 换行,但是我真的不希望我的用户每次想要一个新行时都必须写 '/n'行,他们应该只需要按键盘上的回车键。
换行符存储在数据库中,所以我不知道为什么它没有回显。有人可以帮忙吗?
不确定代码是否需要,但我会发布它以防万一。
while($wallposts = mysql_fetch_assoc($getwallposts)) {
$postid = $wallposts['id'];
$postedby_username = $wallposts['postedby'];
$wallpostdate = $wallposts['dateposted'];
$wallpost = $wallposts['post'];
$querypostedby_info = mysql_query("SELECT * FROM `users` WHERE `username`='$postedby_username'");
//get the info above
if (mysql_num_rows($querypostedby_info)===1) {
$getpostedby_info = mysql_fetch_assoc($querypostedby_info);
$postedby_id = $getpostedby_info['id'];
$postedby_profilepicture = $getpostedby_info['profilepicture'];
}
//display the posts
$wallpoststicker =
"
<div id='wallpost-container'>
<div id='wallpost-header'>
<img src='$postedby_profilepicture'><div id='wallpost-header-by'><a href='/profile.php?id=$postedby_id'>$postedby_username</a> said:</div>
<div id='wallpost-date'>• $wallpostdate</div>
</div>
<div id='wallpost-content'>
$wallpost
</div>
</div>
";
}
【问题讨论】:
-
尝试将它们包含在
<pre>标签中,如下所示:...<div id='wallpost-content'><pre>{$wallpost}</pre></div>...