?
Solved

echo new line in textarea

Posted on 2006-06-29
6
Medium Priority
?
483 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:ray-solomon
[X]
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
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 17014038
Don't use this line!
$output = str_replace("\n", '', nl2br($input));
It replaces \n (which is a newline) to <br />
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17014041
Just use:
$output = $input;
0
 
LVL 10

Author Comment

by:ray-solomon
ID: 17014071
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]
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Author Comment

by:ray-solomon
ID: 17014096

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]
0
 
LVL 10

Author Comment

by:ray-solomon
ID: 17014104
Here is how I am getting the form values:

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

if (isset($_POST['field1'])) { $output = $kw; }
0
 
LVL 8

Accepted Solution

by:
Autogard earned 500 total points
ID: 17014146
 $string = "Hey there\r\nHow are you\r\ntoday?";

  $output1 = $string;
  $output2 = "\"" . str_replace("\r\n", "\"\r\n\"", $string) . "\"";
  $output3 = "[" . str_replace("\r\n", "]\r\n[", $string) . "]";

  print "<textarea>";
  print "$output1";
  print "</textarea>";

  print "<textarea>";
  print "$output2";
  print "</textarea>";

  print "<textarea>";
  print "$output3";
  print "</textarea>";

yields:

Hey there
How are you
today?

"Hey there"
"How are you"
"today?"

[Hey there]
[How are you]
[today?]

(but in textareas of course)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

762 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