Forum Moderators: coopster

Message Too Old, No Replies

too many breaks lines with nl2br (new ones added when I edit)

can I limit it to just one?

         

walkman

12:25 pm on Mar 7, 2005 (gmt 0)



hi,
I'm not a php programmer but I have someone doing something for me, and evey time I edit a page a new break line is added. I will edit these pages 50 times or more a year so you can see why I need to limit to one <br />. nl2br is needed because I will cut and paste some stuff to transfer the data, and later on it's easier to add stuff.

I think it can be done but he's having some problems with this. How can the <br /> lines be limited to just one? What can I "suggest"?

thanks in advance,

[edited by: trillianjedi at 1:33 pm (utc) on Mar. 7, 2005]

Warboss Alex

3:38 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



PHP wouldn't be adding a <br />, how exactly are you editing?

walkman

6:47 pm on Mar 7, 2005 (gmt 0)



thanks for asnwering...
Ok,
I'm adding things in a mysql database via php, let's say for New York City. I have a field that says description /about. On the php code it is
"$about=nl2br($about);".
If I cut and paste :
newyork city is a city blah
blah blah
blah

etc. in that field, the formating will be saved as <br/> lines will be added. If I edit it again the next minute or month, a new <br/> will added in the same place where the first one was, and now they will double spaced. Essentially, a new br line will be added every time I edit that file.
After 2-3 times I will see this:
newyork city is a city blah<br /><br /><br />
blah blah<br /><br /><br />
blah<br /><br /><br />
and is spaced accordingly on the page.

I hope I made sense...

jezra

6:59 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



I've run into this one as well. When using nl2br, PHP adds <br /> to the text just before the newline. However, the Newline is not removed. If your were to use nl2br on the text again, another <br /> would be added. If you are editing the text in a html form, you may want to replace the "<br />" with an empty string before displaying text in the form.

jatar_k

7:12 pm on Mar 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when I select for edit I use

str_replace('<br />',"",$myvar)

then when I update I use

mysql_escape_string(nl2br(stripslashes($mynewvar)));

walkman

8:23 pm on Mar 8, 2005 (gmt 0)




thanks guys,
will suggest what jatar_k said. I can't manually remove the <br /> because it would be 100 times harder than disabling nl2br and manually entering the <br>s once..