Click to See Complete Forum and Search --> : Return key causing a line feed in a txt file


gogelpot
04-22-2008, 12:10 PM
Hi,

I have a form where a client will fill in their postal address in a <textarea>. This data is then stored in a data base.

If the client uses the return key any where in the address I have a problem reading the address from the database and writing it into a text file. The return key causes a line feed in the text file.

Is there a way to read the return key and then remove it befor writing it to the text file.

Could somebody please help me with some ideas?

NogDog
04-22-2008, 01:36 PM
trim() will get rid of any leading/trailing white-space, including newlines.

gogelpot
04-22-2008, 03:03 PM
The Problem is that the newlines is not at the end but in the center of the field .

Like this:

150 Kruispad Brackenfell 7757


Becomes this:

150 Kruispad
Brackenfell
7757


becuase the client types it in as in the bottom quote in the <textarea>.

When I get the field out of the DB to write into the text file it gives a line break like in the bottom quote. I need it to look like the top quote.

NogDog
04-22-2008, 03:16 PM
Firstly, if it should only be one line, then a <input type="text"> element would be much more appropriate than a <textarea> element in your form. Anyway, to remove all newlines:

$address = preg_replace('/[\r\n]+/', ' ', trim($address));