Results 1 to 8 of 8
  1. #1

    textarea, mysql, php

    hey,

    im working on a forum for my website, and for the signatures they:

    enter it into a <textarea>
    it goes through htmlspecialchars()
    gets put in the database
    then is selected and put below their post

    thats all great, right?

    no
    i put in:

    Livin` php style,

    Xbox Live Gamertag: Hybrid Blade,
    Nickname: DM PA,
    Proud member of the Dark Minions Clan:
    www.gamenationx.com/darkminions/


    and below their post it reads:

    Livin` php style., Xbox Live Gamertag: Hybrid Blade, Nickname: DM PA, Proud member of the Dark Minions Clan: www.gamenationx.com/darkminions/


    i have no idea whats wrong or how to fix it...

    any ideas?


    EDIT: btw. same thing happens with their actual post....

  2. #2
    Join Date
    Dec 2002
    Location
    Fort Worth
    Posts
    434
    You need to properly set the "wrap" attribute of the textarea tag. <textarea wrap='physical'> will retain the newlines entered by your users.

  3. #3
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    Except you should be aware that 'wrap' is not a valid attribute for textarea under the XHTML 1.0 transitional standard (or even under HTML 4.01)

  4. #4
    Join Date
    Jan 2002
    Location
    Adelaide, Australia
    Posts
    405
    nl2br() is what you need
    it converts /n/r (which is what's in the text area) to <br /> in html.

    so nl2br($text); before it goes into the database

  5. #5
    Join Date
    Dec 2002
    Location
    Fort Worth
    Posts
    434
    but will there even be newlines in the text if wrap='physical' is not used. and if wrap is not standard, what is the solution?

  6. #6
    Join Date
    Jan 2002
    Location
    Adelaide, Australia
    Posts
    405
    you get the new line by hitting enter That's a hard break (/n/r).

    Wrapping is for easy reading, as far as all things are concerned it's just a long string with no breaks at all.

    Wrapping in textarea's can be done with CSS now

  7. #7
    Originally posted by platinum
    nl2br() is what you need
    it converts /n/r (which is what's in the text area) to <br /> in html.

    so nl2br($text); before it goes into the database

    awesome. thanks it worked

  8. #8
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    Originally posted by platinum
    you get the new line by hitting enter That's a hard break (/n/r).
    Depends on your operating system as Linux only sends a \n whereas windows uses \n\r

    Very annoying when you are trying generate email or http headers as they terminate with a double CRLF but differently under the two OS's

Posting Permissions

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