Preserve Line Breaks From TextArea When Writing To MySQL

前端 未结 7 2250
我在风中等你
我在风中等你 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:45

    Got my own answer: Using this function from the data from the textarea solves the problem:

    function mynl2br($text) { 
       return strtr($text, array("\r\n" => '
    ', "\r" => '
    ', "\n" => '
    ')); }

    More here: http://php.net/nl2br

提交回复
热议问题