Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

storing textarea field into db without carriage return

Posted on 2004-09-24
6
426 Views
Last Modified: 2012-06-27
Dear All,

I have a html form with a textarea for input. The data submitted would be sent to mysql db, I found that the textarea input cannot be stored properly to db if user press "enter" to make a new line...

I would like to replace the carriage return (/n/r) with  a space, but it does not work..I also tried the nl2br function, but the carriage return still exists...

it messes up my csv file outputed by php.. so how can I remove the carriage return from the input?

Thanks
0
Comment
Question by:esther_6694
  • 2
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12140640
You could try

$field = str_replace(array("\n","\r"), array('\n','\r'), $field);

nl2br replaces newlines into <br/>newlines, so therefor the newlines indeed wll not be actually removed to my knowledge.

-r-
0
 

Author Comment

by:esther_6694
ID: 12140680
thanks, but it does not work..

in mysql, I can see a long space at the carriage return position and it makes the data can only be shown in 2 line for a row of record..



0
 
LVL 49

Accepted Solution

by:
Roonaan earned 100 total points
ID: 12140698
You want it to be totally removed at all?

Then the line below should do the trick:

$field = str_replace(array("\n","\r"), array('',''), $field);

-r-
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question