Jump to content

[SOLVED] Removing newlines from textarea


Bricktop

Recommended Posts

Hi all,

 

I'm building a simple application which writes data to a text file.  Each line of this text file is treated as a separate "database entry" and the data on each line separated by ||.

 

So for example, the text file looks like:

 

A Name||11 The Road||The Town||The City
A Name||23 The Road||The Town||The City
A Name||78 The Road||The Town||The City
A Name||90 The Road||The Town||The City

 

This works great but on the data entry screen I'm using two textareas.  If the users presses the enter key in the textarea and then submits, it breaks the text file up so it looks like:

 

A Name||11 The Road||The Town||The City
A Name||23 The Road||The Town||The City
A Name||78 The Road||The Town||The City
A Name||90 The Road||The Town||The City
A Name||200 The
Road||
The
Town||
The City

 

Obviously, the code which outputs the above then goes wrong and everything breaks :(  When writing the data to the file I've tried using trim($variable) and nl2br($variable), I've also tried using trim and nl2br on the POSTed data before it's written to the text file but that doesn't work either.  (If using nl2br I get the <br />'s appear in the text file but the carriage return is still present.)

 

Any ideas?

 

Thanks in advance.

Link to comment
Share on other sites

Yes, if they enter:

 

A Name 11 The Road The Town The City (without pressing enter in the textarea box) it works fine and the data gets written to the text file properly.

 

If they enter:

 

A Name

11 The Road

The Town

The City

 

(obviously pressing enter at the end of every line) the data gets written to the text file but at the end of each line it starts a new line in the text file.

 

So instead of

 

A Name||11 The Road||The Town||The City

 

I get:

 

A Name||

11 The Road||

The Town||

The City

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.