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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    86
    Thanks
    5
    Thanked 1 Time in 1 Post

    textarea basic formatting?

    I've got an HTML textarea that is the input for a large bit of text.

    Sometimes, the user will hit return on their keyboard and this will of course drop the text after onto the line below.

    The problem I'm having is that I want it to display like it is entered when it is output from the database, but I have no idea how to do this without using an javascript based WYSIWYG HTML editor which I don't want to do as it is massive overkill for what I want to do.

    Any ideas?

    Cheers

    The Moose

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    86
    Thanks
    5
    Thanked 1 Time in 1 Post
    Quote Originally Posted by abduraooft View Post
    Thank you!!

    Is there a reverse? i.e. br2nl?? (i.e. when editing the text in another textarea)

    Cheers

    The Moose
    Last edited by the moose; 10-20-2009 at 06:22 PM.

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Please notice that nl2br() does not replace line end characters with <br />. It just adds <br /> after line end characters.

    It is better not to store the text to the database with <br />. You only apply nl2br() to the text extracted from the DB when you output the text in HTML context.

    If you do not store <br /> or any other HTML formatting to the database you could show and edit the text in as many textarea fields as you need. You simply would not need and reverse function for nl2br().

    There is no standard reverse PHP function for nl2br(). You could easily write it e.g. using str_replace() but I do not see where you could possibly need it ...


  •  

    Posting Permissions

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