views:

53

answers:

1

I'm using

var retval = value.replace(/<br[\s\/]?>/gi, '\n');

To strip the <br> tags from the textarea and nl2br('$_POST('newValueHere')') to insert into my database and to return back to jeditable to display the edits. The only problem I'm having is that each click on the editable field seems to make all the <br> tags be written twice? This makes no sense, does anyone have any ideas what could be going on?

+2  A: 

nl2br doesn't replace linefeeds, it inserts <br> tags before them. Your regex turns <br>\n to \n\n, then nl2br turns that into <br>\n<br>\n. You need to remove the linefeed following the tag if there is one:

var retval = value.replace(/<br\s*\/?>\n?/gi, '\n');
Alan Moore
This has fixed it, I see what your saying about the regex, Thanks very much!
st3