daniel daniel - 4 months ago 12
PHP Question

Read Enter text in php

I have a problem. I have a text that called from database. In database, the text has an enter text. Here is the picture:

enter image description here

But in my website, it has no enter. Here is the picture.

enter image description here

How to read enter in php?

Here is my code:

<?php
$ambil = mysql_query("SELECT * FROM blog WHERE id_blog = '" . $id . "' ");
$deskripsi = $tamp->deskripsi;
?>

<html><body>
<p><?php echo $deskripsi; ?></p>
</body></html>


Thank you before :)

Answer

Try <p style="white-space: pre">.

You could also replace the newlines in the text with <br> tags.

The latter can be accomplished like this (hat tip to @andrewsi):

<p><?php echo nl2br($deskripsi); ?></p>