So, i have in my database a text for example :
blabla
bloblo
blibli
I can see newlines if i look my text in my database. This text is from a textarea.
I have an Ajax request for get this text from my database.
In my php script, i do : echo json_encode($mytext)
and in my ajax success i have my text in the var data
.
But when i try to display this text data on my page, i loose all new lines. All my text is in on single line.. Any ideas ?
It's because the newline characters () aren't new lines in HTML. In HTML you have to add either paragraphs (
<p>
) or line breaks (<br>
) tags to accomplish this, depending on your scenario. I imagine you need to break line.
You can convert new lines into <br>
tags using nl2br.
Reference: http://de1.php.net/nl2br
User nl2br function to display the data same as you entered in textarea.