[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

echo new line in textarea

Posted on 2006-06-29
6
Medium Priority
?
485 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 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 …
Suggested Courses

656 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