0
$whichwrong = "The following questions were not answered correctly: \n\n";
$whichwrong .= "Question Number: $questionNum || Your Answer: $userAnswers[$s][$q]\n";
echo $whichwrong;

显示:

以下问题未正确回答: 问题编号:2 || 您的答案:b 问题编号:4 || 您的答案:c 问题编号:5 || 你的答案:一个问题编号:1 || 您的答案:b 问题编号:3 || 您的答案:b 问题编号:1 || 您的答案:b 问题编号:2 || 你的答案:一个问题编号:1 || 您的答案:b 问题编号:2 || 你的答案:b

为什么"\n"不能正常工作?

同时这工作得很好:

$totalValue .= "Correct: {$correct}\n";
$totalValue .= "Wrong: {$wrong}\n";
4

2 回答 2

2

用于nl2br插入 html 换行符 ( <br />)

echo nl2br($whichwrong);

正常\n被浏览器视为普通空格。

于 2013-06-18T15:42:09.690 回答
2

如果您在浏览器中查看它,您需要使用<br>- 您也可以使用该nl2br()功能。如果您在控制台中,请尝试\r\n

于 2013-06-18T15:42:24.490 回答