grief with printf(), padding and alignment of text
| From: | Robert E. Harvey, M.D. | Date: | Tue, 11 Feb 2003 23:21:41 +0000 |
| Subject: | grief with printf(), padding and alignment of text | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-135253@lists.php.net to get a copy of this message | ||
I'm running PHP 4.2.2 and I'm having trouble with the printf() function. I want to be able to print data in space padded fields with the alpha strings left justified and the numeric strings right justified. For some reason I can't get printf() to pad with spaces. It pads with " "-s and right aligns the data
For example this code: printf("%' -20s %' 20s %' -20s<br>\n",$algen, $calc_amt, $range);
returns this output: Algae 292 very high
which shows no padding.
This code: printf("%'-20s %'20s %'-20s<br>\n",$algen, $calc_amt, $range);
returns this output: ---------------Algae 292 -----------very high
which pads only the first and third strings with "-" and not " "and right justifies to the right and not left.
This code: printf("%'\ -20s %'\ 20s %'\ -20s<br>\n",$algen, $calc_amt, $range);
returns this output: Algae 292 very high
with no padding and no justification.
How do I get printf() to work properly?