Web Hosting Talk







View Full Version : textarea, mysql, php


Gamenati
05-28-2003, 05:15 PM
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....

jb4mt
05-28-2003, 06:08 PM
You need to properly set the "wrap" attribute of the textarea tag. <textarea wrap='physical'> will retain the newlines entered by your users.

Rich2k
05-28-2003, 06:18 PM
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)

platinum
05-28-2003, 06:25 PM
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 :)

jb4mt
05-28-2003, 06:30 PM
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?

platinum
05-28-2003, 06:33 PM
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 :)

Gamenati
05-28-2003, 07:31 PM
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

Rich2k
05-29-2003, 04:35 AM
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