I am storing the text of a textarea
in my database , and in this I can see how the text is stored respecting the existing line breaks.
The problem is that when collecting this data with PHP and printing it inside a label <p>
, the line breaks are not shown , but everything is together.
When receiving the text you have in the textarea, the text is saved verbatim; that is, neither labels
<br/>
nor<p>
. So when you have saved the text, the line breaks have been saved with the character\n
.When you type text on the screen, line breaks (
\n
) in HTML are displayed as spaces; That's why all the text comes out all together. To prevent this from happening to you, you'll need to replace line breaks with elements<br/>
. You can easily do this like this:The function
nl2br
inserts HTML line breaks before all newlines found in a string. More information: