Forum Moderators: coopster

Message Too Old, No Replies

How come the <br> marks never come up?

         

bobnew32

1:19 am on Jul 6, 2003 (gmt 0)

10+ Year Member



I'm using a regular form and php based script to simply add a row to my mysql database with php. One of the inputs is called $review where people input a review. Now this would be multi paragraphs and when they try to do that, (when its in the text area they hit enter to start a new line) it would never show the break when its inputed.

If I need to show a lil code to help ya I will, but how would I got about doing this? I know its able to be done, probobly easy too... Thx everyone!

hpche

2:20 am on Jul 6, 2003 (gmt 0)

10+ Year Member



Sounds like you need the nl2br( ) function. For instance, just add some code like

$review = nl2br($review );

Into your script, and it will replace the textarea new lines with XHTML <BR /> tags for you.

DrDoc

2:43 am on Jul 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it would never show the break when its inputed

So, you don't want the break, right?

$input = preg_replace("/\n/","",$input);

bobnew32

3:50 am on Jul 12, 2003 (gmt 0)

10+ Year Member



DrDoc, is that last code you provided undo the process that $review = nl2br($review ); causes? I hope so...

The process $review = nl2br($review ); works for when I add a review perfectly, and it displays fine. But when I got to edit it, the </ br> lines show up. This confuses me and the people that use the system. So is there a way of reversing the process so that when you go to edit it in the <text area> the </ br> doesn't show and appears how it was when I first added it?

Just for clarification, after somones edits and resubmits, the system does do nl2br on the new data.

DrDoc

4:58 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To undo nl2br, you need to do this:

$review = preg_replace("/<br>/","\n",$review);

Or, if XHTML conforming:

$review = preg_replace("/<br \/>/","\n",$review);

vincevincevince

10:06 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember to escape < and > :

$review = preg_replace("/\<BR \/\>/","\n",$review);

If your site isn't massive - then it's probably easiest to put $review through nl2br() every time you output the page

So you'll store without the <BR />, then echo nl2br($review) for the output.. :)