Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:32:40+00:00 2026-06-07T14:32:40+00:00

I have a textarea. User inputs text into the textarea, which can contain line

  • 0

I have a textarea. User inputs text into the textarea, which can contain line breaks for formatting purposes. I save this text to the mySQL database as is without adding HTML br breaks. This looks like “text blah blah.\n\nText2 blah blah.” in the database record.

I display the text on a regular HTML page using echo nl2br($text); and the text is nicely formatted, with two line breaks showing up as a two sentences with a blank line between them.

When I send the same text to a textarea prepopulated for the user to edit their original entry, I use the following code:

<textarea><?php echo $text;?></textarea>

I expect that I would get a textarea filled with text that includes some double line breaks as are stored in the database. I don’t use nl2br in this case, because doing so would just literally show the HTML characters (not actually create line breaks — in other words display to the user the 6 characters of the br). Instead, what I get is stripping of any double new lines, so that two new lines back-to-back are now single new lines. The single new lines don’t get stripped out completely — they just stay single new lines.

So, in short, when I send text with formatting that should include a blank line between lines of text, what I get is only single new lines, breaking the important formatting of the text).

How can I preserve all of the newlines when outputting text from the database to a textarea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:32:45+00:00Added an answer on June 7, 2026 at 2:32 pm

    This works for me:

    <?php
    $txt = "line1\nline2\n\nline4\nline5";
    ?>
    <html>
    
    <body>
    
    <form>
    <textarea rows=10><?php echo $txt ?></textarea>
    </form>
    
    </body>
    
    </html>
    

    Note the lack of line3 text and the double \n\n. Loading this form in Firefox gives me a blank line between the line2/line4 text, as expected.

    Check that your text isn’t being mangled elsewhere, and really is in the database as a double-line break.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textarea where user can edit some text and it accepts HTML.
I have an app where a user can input text in a textarea. I
I have a webpage that the user inputs data into a textarea and then
I have a textarea in which the user enters the following data: Paul:Nine, Rome
I have a textarea, where the user can add their comments. Now after adding
I have a litle problem with my text encoding, when user filed textarea field
I have a text area where user can write his SMS. You all know
I have the following Javascript to copy the user's textarea input in this iPhone
I have a system which allows users to enter HTML-reserved characters into a text
A user will input text in a textarea. It is then inserted directly into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.