TwelvestoneBack End

Multiple line breaks


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Suzy
 
2010-02-02

Hi guys, I've got a HTML form where people can insert some text into a mutiilne text box and then inserts this into a database. Problem is every time the text is changed it inserts a line break at the end until eventually it has loads of line breaks and breaks the code. Does anyone know how I can search and replace multiple line breaks and replace it with just one? I presume this will have to be done in a loop until there are no more than one line break in a row? Any ideas? Thanks, Suzy k

Technomancer
 
2010-02-02

Hi Suzy,

I assume that you mean you have <textarea> element on the form?

Is there any server side processing going on before you insert into the db (converting line breaks to <br&gt) that could be adding in the extra line breaks?

I assume that there is some sort vbcrlf replace happening somewhere?

scudsucker
 
2010-02-02

'' untested ASP myText=Replace(myText, "", "") myText=Replace(myText, vbcrlf & vbcrlf , vbcrlf )

Stickman
 
2010-02-02

If I were doing it in PHP, I'd replace all tags with line breaks ("\n"), do a trim(), and then replace the line breaks with s. Presumably there's an ASP equivalent of trim().

Suzy
 
2010-02-02

Yes it is a but there is no converting anything before it goes in the database or any other replaces going on.

Suzy
 
2010-02-02

Stickman - there is trim in ASP so that might be the best way to go - I'll give it a try k

Suzy
 
2010-02-02

Well for anyone wanting to do it in ASP I did it a rather long winded way by doing the following when the results are outputted:

' Remove all trailing line returns after text pDesserts = rsMenus(Trim("Desserts")) pDesserts=Replace(pDesserts, " ", " ") pDesserts=Replace(pDesserts, vbcrlf, " ") pDesserts=(Trim(pDesserts)) pDesserts=Replace(pDesserts, " ", vbcrlf) pDesserts=Replace(pDesserts, " ", " ")

But then like a muppet I realised I need to do it before it goes in the database!

Technomancer
 
2010-02-02

The issue here Suzy, is why the extra line breaks are appended in the first instance.

Want to post the code that takes the form input and inserts it to the db? Is there some data sanitising that might be causing the problem?

Suzy
 
2010-02-02

All I've got is this:

rsUpdate.Fields("Desserts") = (RTrim(Request.Form("Desserts")))

There is no data sanitising as it just an application on a computer and not web based.

Suzy
 
2010-02-02

Oh well the code sorted it which is the main thing. It's something I developed nearly three years ago and I'm just trying to quickly fix a few bugs for them so the main thing is they will be happy.

Thanks for all your help guys k

Stickman
 
2010-02-02

When it comes to fixing old code, as with so many things, quick'n'dirty is the way to go. :thumbsup:

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Multiple line breaks