Domanda

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?

È stato utile?

Soluzione

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 />

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top