View Full Version : <br> in a textarea
12-10-2003, 03: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>??
12-10-2003, 03:38 AM
Use a newline in textareas, no BRs.
12-10-2003, 03: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);
12-10-2003, 06:22 AM
Why use regex? Just use nl2br() (http://www.php.net/nl2br)
12-10-2003, 02: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.
12-10-2003, 06: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.
12-10-2003, 08: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
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.