I’ve made a site where the user can type somthing in a textarea. The text is then saved to a databse I have at phpMyAdmin. However, when I retrive the data from the database, and ‘echo’ it on the screen, all the line breaks the user have included, is gone.
Does anyone have a solution for this?
I’ve tried with different things like including a button for ‘new line’ in the UI, but that’s not very convenient. I wonder if there’s any other way of displaying the line breaks?
2
Answers
You might want to use the nl2br() function:
This will echo:
If you want to display the text exactly as it was entered on a web page, perhaps a
<pre></pre>
block may work best for you.It would be best if you did more to sanitize any user-provided text you intend on returning to a browser, though, to avoid XSS and other exploits.
For example, what if a user sent you a script block, and you returned that to any one’s browser?