PDA

View Full Version : Changing textarea newline to <br>


RealmRPGer
03-11-2005, 04:53 AM
I'm not sure if this should go in javascript or php, but I'm guessing javascript since I think php gets the submit post without any indication of newline.


I added a reply function to my website using an html textarea input. Is there anyway to convert the newlines in that box into <br> tags? Does javascript see those as \n?

shwaza
03-11-2005, 09:38 AM
Well i dunno about javascript, but it's very easy to do with PHP.

Say that you had a text area named "blah". This is what you would do:


<?php
if($_POST['blah']){
$blah=$_POST['blah'];
$blah=str_replace(chr(10), "<br>", $blah);
}
?>

And of course you can make it submit the form to somewhere if you want :P

RealmRPGer
03-12-2005, 01:35 AM
Ah. Okay. I wasn't sure if the text got its newlines pre-formated out when you went to the next page. Haha, I guess I should have tried to do it in php first. =p