0

I am making a form in html and there is a <textarea> tag in that form. first.php is like:

<form method="post" action="next.php">
    <textarea name="desc" raws="4">Here, Its Text Area</textarea>
    <button type="submit" name="submit">NEXT BUTTON</button>
</form>

And next.php is like:

<?php
if(isset($_POST["submit"]))
{   
    $desc = $_POST["desc"];

    echo $desc; //<------ ECHO LINE 1
}
else
{
    header("location: first.php");
    
}

And when I am typing this message:

Hi,
Helo there,
I am LakshyaK2011.

And echoing in it next.php, in echo line 1 (See In next.php's code)
It is displaying like this:

Hi, Helo there, I am LakshyaK2011.

is there any fixes to it? Thanks,

I have tried:
(I didn't know what to do so I tried nothing)

I have expected:
I will enter:

Hi,
Helo there,
I am LakshyaK2011.

And it will print same as that.
Not like: Hi, Helo there, I am LakshyaK2011.

James Z
  • 12,209
  • 10
  • 24
  • 44
LakshyaK2011
  • 102
  • 10
  • Does this answer your question? [Preserve line breaks in textarea](https://stackoverflow.com/questions/30593103/preserve-line-breaks-in-textarea) – HPierce Nov 12 '22 at 16:10

1 Answers1

0

To display new line in HTML format, you need something such as <br>

So Change

 echo $desc; 

to

 echo str_replace(chr(13), '<br>',$desc); 

Alternatively, use nl2br()

https://www.php.net/manual/zh/function.nl2br.php

Ken Lee
  • 6,985
  • 3
  • 10
  • 29