I've tried nl2br()
as well as ALL of the methods listed in the comments here. The problem I have is that even though they do insert the <br/>
, the
still remains in the text.
This is what I was originally doing:
<?php
$stmt = $db->prepare(...)
$stmt->execute();
while ($row = $stmt->fetch()) {
$tldr_clean = nl2br($row['tldr']);
$body_clean = nl2br($row['body']);
?>
<section>
<h2 class="tldr"><?= $tldr_clean ?> <?= $row['score']?>/10</h2>
<p class="body"><?= $body_clean ?></p>
<p class="reviewer">Written by <?= $row['name'] ?></p>
</section>
<?php
} ?>
Assuming $row['body']
is "Hello
Goodbye"
, the output in the html is:
Hello
Goodbye
I've tried using the method nl2br()
directly with the string that is stored in the database, and it works correctly. So I'm guessing the problem is in calling the method with a variable? How can I fix it?
Edit:
String is stored as NVARCHAR2 in an SQLite table.
String stored in database:
"Fusce vitae purus tristique, efficitur dolor et, tristique ante. Aliquam sapien nisl, sagittis id justo eget, placerat ultrices nisl. In tempus sollicitudin mauris ut feugiat. Pellentesque imperdiet risus at ex dictum, sed tempus est pulvinar. Nunc nec leo fringilla diam sodales euismod sed sed odio. Cras mollis, quam at iaculis semper, justo dui maximus tellus, quis dictum urna velit sit amet justo. Curabitur consectetur fringilla arcu, sit amet ultrices est dignissim eget. Etiam non dapibus justo, et semper quam. Suspendisse tristique augue sit amet gravida euismod. Ut tempus metus quis nisl sagittis volutpat. Nam rhoncus diam luctus dictum tristique."