Preserve Line Breaks From TextArea When Writing To MySQL

前端 未结 7 2200
我在风中等你
我在风中等你 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 13:05

    Here is what I use

    $textToStore = nl2br(htmlentities($inputText, ENT_QUOTES, 'UTF-8'));
    

    $inputText is the text provided by either the form or textarea. $textToStore is the returned text from nl2br and htmlentities, to be stored in your database. ENT_QUOTES will convert both double and single quotes, so you'll have no trouble with those.

提交回复
热议问题