user2773749
user2773749

Reputation: 1

Replace all the enters in a text and then replace them all with <br/>

I want to replace the enters in the $content part to <br/> so it actually shows up as enter on my webs

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

?>

But the $str = $content.split("\n").join("<br/>"); Doesn't work as I want it to work. It doesnt output <br/> in the output string to the database. Any one can help me out with this?

Upvotes: 0

Views: 39

Answers (3)

user2994883
user2994883

Reputation: 44

PHP_EOL is quite nice too, have a look.

Upvotes: 0

Wander Nauta
Wander Nauta

Reputation: 19635

That's not how string splitting and joining work in PHP (you're probably thinking of Python).

The easiest way to do this specific task would be to use PHP's builtin nl2br function instead.

Upvotes: 0

yunzen
yunzen

Reputation: 33439

nl2br is the function you are looking for.

$str = nl2br($content);

Upvotes: 1

Related Questions