How can i enable a Break Line or New Line in Textarea when i press the Enter Key ? So that if I press the ENTER it saves in the form of New Line in database.

I have already searched some topics but it hasn't helped me.

Here is my Textarea Code:

<textarea name="post" id="post"  class="valid Post_Text_Area" placeholder="Write something here..." ></textarea>

I tried this JS Code so far. but it hasn't worked for me

JavaScript: How to add line breaks to an HTML textarea?

有帮助吗?

解决方案

Newlines in textarea's are saved into the database by default.

To generate them as Html BR codes, use nl2br($yourTextVariable) $yourTextVariable will be the variable you fetch from database. so use it like this :

<?php echo nl2br($yourTextVariable); ?>

This transforms newline to <br />

其他提示

Another solution is put the output into <pre> tag or just style it with css white-space: pre. It will not swallow multiple spaces.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top