storing textarea field into db without carriage return

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
esther_6694Asked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
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
 
RoonaanCommented:
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
 
esther_6694Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.