I am collecting text from a textarea. The text has line breaks in it. I then save it to a database.
However when I retrieve it from the database and display it back in a textarea for editing, the line breaks are gone and the text turns into one long run-on string.
I would like the line breaks originally there to reappear. How can I make the line breaks appear as they should when inserted back into a textarea?
Note: I cannot just convert them to a <br> because this is going inside a textarea where <br> elements would not get rendered, but just written out as text. I want the actual line breaks.
Everyone is suggesting to convert the line breaks to <br />, however as you stated in your question that's not what you want. You want to display the line breaks in the textarea again. So, what you need here is stripcslashes() - this will strip away \n and give you what you're after, being line breaks in your textarea, not html <br /> tags in the textarea:
PHP: stripcslashes
Usage:
echo stripcslashes($input_text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With