enter in textarea problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

enter in textarea problem

Post by potato »

I have a textarea where i would enter a description.
But my problemisthat if i 'enter' in the textarea, i doesn't save the enter
in my mysql tabel.
How can i fix that?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

you should use the nl2br() function. Look it up in php.net
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Another way...

function convertReturns($input_text) {
$input_text = ereg_replace("\n","<BR>",$input_text);
return $input_text;
}

Then when you're displaying something from the mySQL database that needs to be returned and has those return line thinger majigs just do something like

convertReturns($row['news_article']);
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

...that does the same as nl2br() only that nl2br() is xhtml compliant, replacing "\n" with "<br />\n". In my opinion it's more efficient to use predefined functions when they exist.
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Sorry
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

:) I wrote great number of functions when I first started programming before realizing that there were predefined functions that did the same thing
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

andre_c wrote::) I wrote great number of functions when I first started programming before realizing that there were predefined functions that did the same thing
lol Me too! :wink:
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

i'm sorry, but where do i have to write this?
More information if it is possible.
Newbie, you now. :oops:
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

You can either use the function before you send to the database or after you retrieve it:

Code: Select all

$text = nl2br($text);
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

Thanx
Post Reply