Si8
Si8

Reputation: 9225

Use str_pad() to function as a TAB in PHP

$emptyStr = ".........";
$whichwrong .= "{$Ss[$s]}\n";
$whichwrong .= $emptyStr . "Question: $questionNum || Answer: {$userAnswers[$s][$q]}\n";

Prints out:

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

I am looking to put space instead of the "." I did the following but it did not work:

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

But it did not include the 10 spaces before the "Question..."

Any idea how to resolve it?

UPDATE [RESOLVED]: I used the following and it worked:

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

Upvotes: 1

Views: 571

Answers (1)

user557846
user557846

Reputation:

As the output is being displayed by a browser you want to use HTML (a web browser collapses white-space). Use a tag around the output, or a non-breaking space (&nbsp;) in the code for the desired result.

Upvotes: 2

Related Questions