Reputation: 569
When I press enter in the textarea it goes to a new line, but that new line does not show up when the textarea is submitted. How do I make this work? It should be simple, but from what I have searched and tried has failed.
<textarea style="{ white-space:pre; }"; name="texts" rows="3" cols="40"></textarea>
$texts = $_POST['texts'];
Upvotes: 2
Views: 5364
Reputation: 2670
Probably the issue is that the new line is showing up, but you're outputing it as html, so it doesn't conserve that new line. You need to convert newlines to break tags when you output as html. You can do it like so:
//editing per comment advice. Apparently this method shouldn't be used since it doesn't replace all possible newline representations, although I dont remember having an issue with it.
//$string = str_replace("\n", "<br />", $string);
//as others mentioned, this is better and easier:
$string = nl2br($string);
Perhaps I'm misunderstanding the question, but this is what I took from it.
Upvotes: 1