Home > Software engineering >  HTML/PHP Entering Multiline Input And I Am Getting it In Single Line. How To Solve It?
HTML/PHP Entering Multiline Input And I Am Getting it In Single Line. How To Solve It?

Time:11-13

LakshyaK2011 Here. 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.

CodePudding user response:

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); 
  • Related