Php and mysqli like line break echo

Hi guys, when I save some part of the text (with line breaks) with php, for example:

this is an example 

in my database I see how I wrote it

enter image description here

But when I repeat this data from my database, I see it wrong.

enter image description here

Can you help me?

My code is

 echo '<p class="date">' . $date . "</p>"; echo '<p class="post">' . $posts . "</p>"; 
0
source share
2 answers

you can check the nl2br function ( http://php.net/nl2br )

 echo '<p class="date">' . $date . "</p>"; echo '<p class="post">' . nl2br($posts) . "</p>"; 
+3
source

The problem is that HTML does not break the line with the newline character. PHP provides a function that converts newlines to <BR> tags. http://www.w3schools.com/php/func_string_nl2br.asp

0
source

All Articles