Why does PHP echo'd text lose its formatting?
Any ideas why formatted text from DB, when echo-ed out in php loses its formatting, i.e. no new lines? Thanks!
Solution 1:
Use nl2br()
.
New lines are ignored by browser. That's why you see all text without line breaks. nl2br() converts new lines to <br />
tags that are displayed as new lines in browsers.
If you want to display your text in <textarea>
, you don't need to convert all new lines to <br />
. Anyway, if you do it... you will see "<br />
"s as text in new lines places.
Solution 2:
Because there are no html tags for formatting! Try the nl2br function.