Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL PHP Save linebreaks in textarea for later display

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.

like image 609
user1260310 Avatar asked Jan 18 '26 06:01

user1260310


1 Answers

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);
like image 113
J Charles Avatar answered Jan 20 '26 20:01

J Charles