line breaks in a textarea

前端 未结 13 1692
北荒
北荒 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:19

    You could use str_replace to replace the
    tags into end of line characters.

    str_replace('
    ', PHP_EOL, $textarea);

    Alternatively, you could save the data in the database without calling nl2br first. That way the line breaks would remain. When you display as HTML, call nl2br. An additional benefit of this approach is that it would require less storage space in your database as a line break is 1 character as opposed to "
    " which is 6.

提交回复
热议问题