Jump to content

FORM related


denny911
 Share

Recommended Posts

Hi,i have many forms on my site and many of those forms have textareas. The thing is, when I insert text into my mySql database, it is all inline text, there's no breaks, even though users were using ENTER key to start new lines in those textareas.is there any simple solution? some javascript, i guess?thanks!

Link to comment
Share on other sites

It's saving the text with linebreaks, HTML just doesn't show a newline character as a line break. Use the PHP nl2br function to convert line breaks to HTML breaks.
thanks for your reply, but would you be so kind to explain me a little bit more that function? how can i use it? will it work on any web server if it works on my localhost (windows vista's IIS 7.0) ? does it require an external library or something like that?
Link to comment
Share on other sites

It doesn't require anything, it's pretty basic.http://www.php.net/manual/en/function.nl2br.phpAll it does is replace the newline character (\n) with an XHTML break followed by a newline (<br />\n). Browsers ignore newlines in text, a browser will show a newline character as a space. It only uses the br tag to show a linebreak, so that function will add the br tags wherever there is a newline character.

Link to comment
Share on other sites

It doesn't require anything, it's pretty basic.http://www.php.net/manual/en/function.nl2br.phpAll it does is replace the newline character (\n) with an XHTML break followed by a newline (<br />\n). Browsers ignore newlines in text, a browser will show a newline character as a space. It only uses the br tag to show a linebreak, so that function will add the br tags wherever there is a newline character.
let's see if i got it right!i'm writing this post in this editing window (that represents my textarea).. i just madeseveral breaks that will be saved as a nl characters in the database.. if programmers didn't use nl2br script, you, justsomeguy, nor anyone else wouldn't see breaks above, but the text would be in one line..so, all i have to do is to put nl2br before my row that contains those breaks: nl2br($row['myTextarea']) ?
Link to comment
Share on other sites

That's right. You can still see the line breaks if you view the source code of the HTML page, the line breaks do show up there, but the browser just shows them as spaces. That's so you can write code like this:<span>text1</span><span>text2</span><span>text3</span>and not have the browser throw a line break after every span. That's just how HTML works.

Link to comment
Share on other sites

That's right. You can still see the line breaks if you view the source code of the HTML page, the line breaks do show up there, but the browser just shows them as spaces. That's so you can write code like this:<span>text1</span><span>text2</span><span>text3</span>and not have the browser throw a line break after every span. That's just how HTML works.
thanks a lot, your replies are always helpful!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...