Link to home
Start Free TrialLog in
Avatar of ray-solomon
ray-solomonFlag for United States of America

asked on

echo new line in textarea

If I type:
1
2
3
into the first textarea box and submit it to a second textarea box, I get:
1<br />
2<br />
3
while using this to process it: $output = str_replace("\n", '', nl2br($input));


I just want the second box to be the same as the first. How do I do this?
Like this:
1
2
3
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Don't use this line!
$output = str_replace("\n", '', nl2br($input));
It replaces \n (which is a newline) to <br />
Just use:
$output = $input;
Avatar of ray-solomon

ASKER

Sorry, let me refine my question. I saw you posted to faster than me editing this question.

I am trying to make the output look like this:
1
2
3
"1"
"2"
"3"
[1]
[2]
[3]

I tried using this, but it does not work properly.

echo $output."\n"."&#34;".$output."&#34;"."\n"."&#91;".$output."&#93;";

result:
1
2
3
"1
2
3"
[1
2
3]
Here is how I am getting the form values:

  foreach ($_POST as $key => $value) {
  $kw = $$key = trim($value);
  }

if (isset($_POST['field1'])) { $output = $kw; }
ASKER CERTIFIED SOLUTION
Avatar of Autogard
Autogard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial