Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PHP echo'd text lose its formatting?

Tags:

php

formatting

Any ideas why formatted text from DB, when echo-ed out in php loses its formatting, i.e. no new lines? Thanks!

enter image description here

like image 322
Roger Avatar asked Jul 15 '11 11:07

Roger


1 Answers

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.

like image 182
daGrevis Avatar answered Oct 22 '22 07:10

daGrevis