sup*_*led 154
两个解决方案:
PHP功能nl2br():
例如,
echo nl2br("This\r\nis\n\ra\nstring\r");
// will output
This<br />
is<br />
a<br />
string<br />
Run Code Online (Sandbox Code Playgroud)将输入包装在<pre></pre>标签中.
hir*_*oki 36
这是我使用的
$textToStore = nl2br(htmlentities($inputText, ENT_QUOTES, 'UTF-8'));
Run Code Online (Sandbox Code Playgroud)
$inputText是表单或textarea提供的文本.
$textToStore是来自nl2br和htmlentities将要存储在数据库中的文本.
ENT_QUOTES会转换双引号和单引号,所以你可以毫不费力地使用它们.