PDA

View Full Version : Getting Breaks from a Form


Navigator
04-07-2008, 08:49 PM
I'd like to make it so on my forums to get it so that you do not need to add a break tag to skip lines. All else is working and now that is what I need to fix. Right now what I have is a message says add [br] to skip a space. I just want to give the members the option to click enter as many times as they need. It's entered into the database with the space(s) skipped, but when it's displayed I guess it needs the break tag to display that break, I have tried this:


$break = "

";
$replace = "<br />";
$message = str_replace($break,$replace,$message);

mlseim
04-07-2008, 09:39 PM
Not sure whether or not you are storing HTML in your database (with the text).
If so, you can do it like this ...

I'm assuming you have some sort of <form> where
you're using <textarea> ... that's where they enter
the text with the carriage returns?

When you read text from database and display your <textarea>,
convert the <br> and <br /> to newlines like this ...
$message=br2nl($message);

function br2nl($str) {
return preg_replace('=<br */?>=i', "", $str);
}

Then, when you save it back to the database, you can
put the <br> back into the HTML, like this ...
$newtext = nl2br($newtext);

(no function needed for that)

Navigator
04-08-2008, 03:28 AM
Thanks for that!