Jump to content

[SOLVED] Echo data on seperate lines


convinceme

Recommended Posts

I have been trying to display the result from the textarea on seperate lines for e.g

if i enter

a

b

c

in the text area it should display the same rather than what it is doing write now "a b c"

Can someone please help me with this?

 

<?php
$action = $_REQUEST['action'];
if ($action == submit) {
print str_replace("\n", "", $_POST['testt']);
}
echo "<form method=post action=?action=submit>";
echo "<textarea name=testt></textarea>";
echo "<input type=submit name=test value=test></form>"
?>

 

I even tried looking in the search area and found this link but that doesn't help either:

http://www.phpfreaks.com/forums/index.php/topic,92732.msg542113.html#msg542113

Link to comment
https://forums.phpfreaks.com/topic/72420-solved-echo-data-on-seperate-lines/
Share on other sites

This works for what you need:

 

<?php
$action = $_REQUEST['action'];
if ($action == submit) {
  $multiple_lines = nl2br($_POST['testt']);
  echo $multiple_lines;
}
echo "<form method=post action=?action=submit>";
echo "<textarea name=testt></textarea>";
echo "<input type=submit name=test value=test></form>";
?>

 

Edit:

You can interchange echo and print depending on what you want to use:

print $multiple_lines;

You can also use the following if you don't want to store the result in a variable:

 

<?php
$action = $_REQUEST['action'];
if ($action == submit) {
  print nl2br($_POST['testt']);
}
echo "<form method=post action=?action=submit>";
echo "<textarea name=testt></textarea>";
echo "<input type=submit name=test value=test></form>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.