替换文本中的所有输入,然后将所有输入全部替换为<br/>

时间:2014-12-18 11:59:43

标签: php

我想将$content部分中的输入替换为<br/>,因此它实际上显示为我的网站上的输入

$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);
}

&GT;

但是$str = $content.split("\n").join("<br/>");并没有按照我的意愿行事。它不会将输出字符串中的<br/>输出到数据库。任何人都可以帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

nl2br是您正在寻找的功能。

$str = nl2br($content);

答案 1 :(得分:0)

这不是字符串拆分和加入PHP的工作方式(你可能在想Python)。

执行此特定任务的最简单方法是使用PHP的内置nl2br函数。

答案 2 :(得分:0)

PHP_EOL也很不错,看看。