Theodore Steiner Theodore Steiner - 1 year ago 131
PHP Question

PHP - Remove Line Breaks From Textarea

I was wondering what I am missing in my code. I have a large form that is pushing all values to a

.csv file
. There are instances of
and every time I put some text content in and add a line break (hit the enter-key) within the
document, any line of text after the first breaks the flow of the values within the
, and starts a new line.

I've tried checking taking the value via php and removing any spaces or breaks, but it doesn't seem to be working.

Can anyone tell me what I am missing?


<textarea id="fianlCommentsText" name="fianlCommentsText"></textarea>


$finalCommentsText = $_POST["finalCommentsText"];
function finalCommentsLineCheck()
global $finalCommentsText;
preg_replace( "/\r|\n/", "", $finalCommentsText );

Answer Source

The "choice" of \r or \n requires parens:

preg_replace( "/(\r|\n)/", "", $finalCommentsText );

Try that?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download