Search code examples
phpjavascripthtmlonkeyuponkeypress

Create a <br /> when you press Enter


I have made a textarea form where you can change your description and like in my previus question I asked if there was any way of having banned tags. But now is there any way of when you press Enter that a <br /> will be set in the textarea so that the user doesn't have to type in <br /> every time they want a line break?

I thought of something like if it can find places where there's nothing, but would this work? I'm not familiar with onpress events... Or if it checks the input after the user has pressed submit and then it checks for line breaks.

I have seen this on YouTube , this site and a lot of other sites too.


Solution

  • In PHP, you can use the nl2br() function to replace any newlines with <br /> tags.