Forum Moderators: coopster

Message Too Old, No Replies

I still dont understand the break marks!

         

bobnew32

4:13 am on Sep 14, 2003 (gmt 0)

10+ Year Member



Ok I have a regular form that takes the information thats in a text area and inserts it into a database. Then another form draws the information out of the db to display it.

My problem is that doing that there are no breakmarks! Someone told me that if I use a textarea there are </br>'s that are automatically added by mysql. Then when I want to display it I use the code

str_replace("\n","<br/>",$str); for the string is the stuff I want to display. But this doesn't work! Please help!

vincevincevince

8:20 am on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



when you want to display, use nl2br($string)

bobnew32

1:20 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Ok thats all good, displaying it 100% works. But now, I have to edit the data. For that to happen, its gonna appear in a text area, but when I put it into a text area, this is the code that appears:

Yeah me time to type away
<br/>
<br/>Yeah me time to type away

How do I get the break marks to go away when I wanna edit it, but have them work?(ie still have lines where they werer supposed to go) Hopefully you understand.

MonkeeSage

2:55 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not familiar with mySQL, and don't know PHP, but your replace is reversed judging from the situation you described...

str_replace("\n","<br/>",$str);

What this is doing is taking any "\n" (newline) in $str and converting it to "<br/>"...odds are that this is why you have <br/> showing up...you need to switch the order...

str_replace("<br/>","\n",$str);

I would also assume you need to assign the return of str_replace() to a variable and then access that variable to fill in the textarea. I doubt the method operates inline, though as I mentioned I'm not familiar with PHP, so you should probably check the documentation for str_replace() if you can.

I think you'd basically end up with something like...

$ta = str_replace("<br/>","\n",$str);
...
echo "<textarea ...>";
echo ta;
echo "</textarea>";

Jordan

vincevincevince

2:55 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



like i said before ;-)

when you want to DISPLAY pass it through nl2br

i.e. store the text as it comes from the input - then you can edit THAT text... or display nl2br(THAT text)

mogwai

3:13 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



As vincevincevince said, but also, if you're displaying it in a textarea just echo it straight from MySQL, the line breaks will be preserved.

bobnew32

3:52 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Thx everyone, I figured it out. Thx for all your help, this concept took me forever to get, and its essential to alot of php so thx alot!