Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    Northfield, MA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preserving Line Breaks

    Hi, I was just wondering if there is an easy method of preserving line breaks from a submitted form. So like, I have a textarea in a form, and I need to keep the line breaks the user enters, and store what the user entered in a MySQL table. I was thinking about \n but I'm not too sure that'll work at all. Thanks!

    Ah, I forgot to mention, I need to redisplay this data with the entered line breaks.
    I'm not always the most helpful, but I'm trying :P

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    Store the data from the textarea as it is, and when outputting data to the browser, use the following function

    nl2br

    cheers,
    Ess

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    if you use

    PHP Code:
    $_POST['blah']; 
    it should work!

    Like

    PHP Code:
    <?php
    $field 
    $_POST['blah'];
    echo = 
    $field;
    ?>

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Please don't post incorrect answers when the original question has already been answered.

  • #5
    New Coder
    Join Date
    Jul 2005
    Location
    Northfield, MA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ess View Post
    Store the data from the textarea as it is, and when outputting data to the browser, use the following function

    nl2br

    cheers,
    Ess
    Wow, thanks, it works perfectly
    I'm not always the most helpful, but I'm trying :P

  • #6
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Will nl2br() make the <br /> tags show up inside the textarea, or do they actually show up as a line break?

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Quote Originally Posted by aedrin View Post
    Please don't post incorrect answers when the original question has already been answered.
    LOL - don't post incorrect answers at any time!
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Will nl2br() make the <br /> tags show up inside the textarea, or do they actually show up as a line break?
    You shouldn't use nl2br() if you are echoing the value within <textarea> tags-- any text within those tags will show up in the input box automatically wrapping each line to fit inside the box (just as it wraps lines are you are typing into a box).

    So that was a long answer to your question-- short answer, Yes, you will see the <br /> within the textbox if you use nl2br() in that instance.

    nl2br() is handy when displaying the text normally (within <p> tags for example).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •