Solved

echo new line in textarea

Posted on 2006-06-29
6
477 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 125 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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…

772 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