line breaks in a textarea

前端 未结 13 1665
北荒
北荒 2020-11-27 17:58

I know when saving a textarea you can use the nl2br() or str_replace to change the /n to br tags etc. However what im not sure about how to insert line breaks into a textare

13条回答
  •  旧巷少年郎
    2020-11-27 18:20

    Don't do nl2br when you save it to the database. Do nl2br when you're displaying the text in HTML. I can strongly recommend to not store any HTML formatting in the database (unless you're using a rich HTML editor as well, in which case it would be silly not to).

    A newline \n will just become a newline in the textarea.

提交回复
热议问题