Preserve Line Breaks From TextArea When Writing To MySQL

前端 未结 7 2226
我在风中等你
我在风中等你 2020-11-22 12:25

I\'m using a textarea to enable users to input comments. However, if the users enters new lines, the new lines don\'t appear when they are outputted. Is there any way to m

7条回答
  •  庸人自扰
    2020-11-22 12:46

    Two solutions for this:

    1. PHP function nl2br():

      e.g.,

      echo nl2br("This\r\nis\n\ra\nstring\r");
      
      // will output
      This
      is
      a
      string
    2. Wrap the input in

       tags.

      See: W3C Wiki - HTML/Elements/pre

提交回复
热议问题