Jump to content

Returns/new lines in textarea text?


galvin

Recommended Posts

I have a form that is processed using PHP (post method) and there is a textarea people will enter text into.

After processing, the text is displayed to the user.  However, if the user did a Carriage Return (i.e. hit Enter) when they originally entered the text, that text does NOT show on a new line when displayed later.

 

For example, if they type this into the text area...

 

"Hello there (they hit Enter here)

How are you (they hit Enter here)

Good I hope"

 

It will display like this, all on one line:

 

"Hello there How are you Good I hope"

 

In other words, it doesn't seem to remember that Enter was hit.

 

Is there some way to "preserve" the fact that someone hit the "Enter" key, so that when text is displayed later, it will show the text on a new line if the user in fact hit "Enter" when originally typing it.

 

I am probably not using the right terms in the right spots (i.e. newline, carriage return, enter, etc) but I think you get the picture

 

Let me know if anyone knows how to do this.

 

Thanks!

Link to comment
Share on other sites

when you echo the string, echo it like this

 

<?phpecho nl2br($string);?>

 

http://php.net/manual/en/function.nl2br.php

 

U can use that when putting the information after POSTING too such as nl2br($_POST['text']) . I dont know if you save the info in a database or anything but I usually just save it with nl2br instead of using it later.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.