galvin Posted September 24, 2010 Share Posted September 24, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/214245-returnsnew-lines-in-textarea-text/ Share on other sites More sharing options...
Jocka Posted September 24, 2010 Share Posted September 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214245-returnsnew-lines-in-textarea-text/#findComment-1114830 Share on other sites More sharing options...
BoarderLine Posted September 24, 2010 Share Posted September 24, 2010 Could also look into using strip_tags() Quote Link to comment https://forums.phpfreaks.com/topic/214245-returnsnew-lines-in-textarea-text/#findComment-1114842 Share on other sites More sharing options...
galvin Posted September 24, 2010 Author Share Posted September 24, 2010 Excellent thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/214245-returnsnew-lines-in-textarea-text/#findComment-1114852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.