How to echo an input of an textarea with line breaks?

前端 未结 3 878
深忆病人
深忆病人 2020-12-28 16:08

I\'m using an textarea to send text to my DB.

Screenshot of db:

\"enter

<
3条回答
  •  余生分开走
    2020-12-28 16:47

    When displaying text, use nl2br() to convert newlines to
    tags, i.e., instead of , use .

    By default, browsers display newlines as spaces, therefore they have to be converted to
    tags.


    For those who find this useful - please consider using white-space: pre-line, suggested by Emil Vikström. I'm not a web guy anymore and easily can't verify this, but Boaz says in comments that it is supported by all modern browsers. If so, that should be preferred to using nl2br().

提交回复
热议问题