2013-06-18 20 views
1
$emptyStr = "........."; 
$whichwrong .= "{$Ss[$s]}\n"; 
$whichwrong .= $emptyStr . "Question: $questionNum || Answer: {$userAnswers[$s][$q]}\n"; 

打印出: 「」使用str_pad()在PHP作爲標籤功能

1. Medication Errors: 
.........Question: 2 || Answer: b 
.........Question: 4 || Answer: b 
2. About Restraints: 
.........Question: 3 || Answer: c 
3. About Pain Assessment And Management: 
.........Question: 2 || Answer: c 
.........Question: 3 || Answer: b 
4. About Universal Protocol: 
.........Question: 1 || Answer: b 
.........Question: 2 || Answer: b 

我希望把替代空間 我做了以下,但它沒有工作:

$emptyStr = ""; 
$whichwrong .= str_pad($emptyStr, 10) . "Question: $questionNum || Answer: {$userAnswers[$s][$q]}\n"; 

但它並沒有在之前包括10位「問題......」

不知道如何解決它?

UPDATE【解析】: 我用下面的和它的工作:

$whichwrong .= "<span style='padding-left: 25px;'></span>" . "Question: $questionNum || Answer: {$userAnswers[$s][$q]}\n"; 
+1

您使用的是空字符串作爲填充而不是空間... – Pinoniq

+3

你發這一個網頁瀏覽器(將多個空格減少爲單個空格字符),或在命令行? –

+0

我正在使用Web瀏覽器。 – Si8

回答

2

由於輸出是由您要使用HTML瀏覽器中顯示(Web瀏覽器崩潰的空格) 。使用標籤周圍的輸出,或在代碼的非斷裂空間(&nbsp;)爲所期望的結果。

+0

謝謝。它按我的預期工作。 – Si8