Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用htmlspecialchars的换行符?_Php_Html - Fatal编程技术网

Php 使用htmlspecialchars的换行符?

Php 使用htmlspecialchars的换行符?,php,html,Php,Html,我有一个表单,人们可以在其中输入文本,它会在页面上回响。我使用htmlspecialchars的原因很明显,但目前不允许换行 如果有人键入: "Line one Line two" 结果是: "Line one Line two" 但我想把断线留在那里 以下是我的数据是如何得到回应的: echo htmlspecialchars($row["message"]); 谢谢 您应该能够使用PHP函数nl2br()完成此操作 使用nl2br函数。在htmlspecialchars之后使用其

我有一个表单,人们可以在其中输入文本,它会在页面上回响。我使用htmlspecialchars的原因很明显,但目前不允许换行

如果有人键入:

 "Line one
 Line two"
结果是:

 "Line one Line two"
但我想把断线留在那里

以下是我的数据是如何得到回应的:

echo htmlspecialchars($row["message"]);

谢谢

您应该能够使用PHP函数nl2br()完成此操作


使用
nl2br
函数。在
htmlspecialchars
之后使用其他方法,换行符将被转义。
echo nl2br(htmlspecialchars($row["message"]));