Solved

echo new line in textarea

Posted on 2006-06-29
6
474 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now