문제

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