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

顯示:在PHP不輸出換行符

The following questions were not answered correctly: Question Number: 2 || Your Answer: b Question Number: 4 || Your Answer: c Question Number: 5 || Your Answer: a Question Number: 1 || Your Answer: b Question Number: 3 || Your Answer: b Question Number: 1 || Your Answer: b Question Number: 2 || Your Answer: a Question Number: 1 || Your Answer: b Question Number: 2 || Your Answer: b

爲什麼"\n"不能正常工作?

同時這工作得很好:

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

空格在瀏覽器中,查看源文件崩潰,你會看到你的換行符,使用
元素代替硬中斷; – Orangepill

+1

使用'\ r \ n' - '\ r'是一個回車符,'\ n'是一個新行 – crmpicco

回答

2

使用nl2br插入HTML的換行符(<br />

echo nl2br($whichwrong); 

普通\n通過像正常的空格瀏覽器處理。

+0

'致命錯誤:調用未定義的函數:n12br()in /home/web/i/imed.com 205行上的/htdocs/test.php – Si8

+3

nl2br!!='n12br' 1!= l – bwoebi

+0

nl =新行。 ;)不是新的1 – Jessica

2

如果您正在瀏覽器中查看,您需要使用<br> - 您還可以使用nl2br()功能。如果您在控制檯中,試試\r\n