View Full Version : <br> in a textarea
SDP2006
12-10-2003, 02:27 AM
How can I make it/which function where when ENTER is hit in a textarea it acts as if it was a <br>??
Thanks
Dylan Leblanc
12-10-2003, 02:38 AM
Use a newline in textareas, no BRs.
stoodder
12-10-2003, 02:47 AM
okay so like if you wanted to replace it with <br> like if you were going to enter it into a database?
try using this once:
$string = preg_replace("/(\n|\r)/", "<br>", $string);
Nightfire
12-10-2003, 05:22 AM
Why use regex? Just use nl2br() (http://www.php.net/nl2br)
SDP2006
12-10-2003, 01:03 PM
Nothing is being inserted into a database. It is just being displayed on the next page. When ENTER is hit on the keyboard, I want it to act as if it was a <br> inserted or a \n new line without the user having to put a <br> or \n in the textarea.
Thanks for the responses.
Dylan Leblanc
12-10-2003, 05:39 PM
When a user types in a textarea and uses the enter key, a newline character, "\n", is automatically inserted, they do not need to type anything else, and certinly not the literal \ and n.
If your query is not working echo it instead to see if there are problems with it's syntax.
ReadMe.txt
12-10-2003, 07:55 PM
you can use an onkeypress event in js if u really want <br /> to br written in when the user presses enter, but using nl2br() (link above) on ur input should be good enough
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.