我想将$content
部分中的输入替换为<br/>
,以便它实际上在我的网站上显示为 Enter
$content = $_POST['thread_content'];
$title = $_POST['title'];
$date = date('d-m-Y H:i:s');
$str = $content.split("'n").join("<br />");
$co = db::escape($str);
$ti = db::escape($title);
$id = db::escape($_GET['id']);
$user = user::getVar("id");
db::query("INSERT INTO Topics (topic_subject, topic_date, topic_cat, topic_by) VALUES ('".$ti."', '".$date."', '".$id."', '".$user."')");
//ID IS ID VAN HET BOARD! NIET VAN TOPIC ID!
$result = db::query("SELECT * FROM Topics ORDER BY topic_id DESC LIMIT 0, 1");
while($row = mysql_fetch_array($result)) {
$topicid = $row["topic_id"];
db::query("INSERT INTO Posts (post_content, post_date, post_topic, post_by, post_title, post_board) VALUES ('".$co."', '".$date."', '".$topicid."', '".$user."', '".$ti."', '".$id."')");
header("Location: ?p=Topics&id=".$topicid);
}
?>
但是$str = $content.split("'n").join("<br/>");
不能像我希望的那样工作。它不会将输出字符串中的<br/>
输出到数据库。有人可以帮助我解决这个问题吗?
nl2br 是你正在寻找的函数。
$str = nl2br($content);
这不是字符串拆分和连接在PHP中的工作方式(你可能想到的是Python(。
完成此特定任务的最简单方法是使用 PHP 的内置 nl2br 函数。
PHP_EOL也相当不错,看看。