Re: Zero Filling Integer
From: Chris Hope (blackhole_at_electrictoolbox.com)
Date: 12/21/04
- Next message: tom: "Align help for two seperate php files"
- Previous message: Douglas F.: "Re: headers already sent ..."
- In reply to: Glenn: "Re: Zero Filling Integer"
- Next in thread: Glenn: "Re: Zero Filling Integer"
- Reply: Glenn: "Re: Zero Filling Integer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 22 Dec 2004 08:38:36 +1300
Glenn wrote:
> Brion Vibber wrote:
>
>> Steve wrote:
>>
>>> Is there a way in PHP to zero fill an integer to a specified length?
>>> For instance, if I have a two digit number, and I want to zero fill
>>> it
>>> to four digits, is there a PHP function I can use? Or do I manually
>>> have to add zeros to the front?
>>
>>
>> http://www.php.net/sprintf
>>
>> -- brion vibber (brion @ pobox.com)
>
> Examples on that web page are given for justification of text as well:
>
> printf("[%s]\n", $s); // standard string output
> printf("[%10s]\n", $s); // right-justification with spaces
> printf("[%-10s]\n", $s); // left-justification with spaces
>
> is to output:
>
> [monkey]
> [ monkey]
> [monkey ]
>
> I tried this, but doesn't seem to be working.. anyone know why?
>
> printf("date [%-20s]", $vdat3);
>
> this yields the following:
>
> date ['2004-12-21' ]
>
> Are additional spaces somehow getting surpressed via the HTML?
Exactly. Additional spaces are ignored in HTML when it is parsed and
displayed in the browser. Otherwise any spaces used for formatting your
code would appear in the browser and it would be an almighty mess.
If you look at the source code of the generated page (View|Source) you
should see the spaces there.
If you are wanting to right align columns of numbers you are best to use
a table with the cell align property set eg:
<table>
<tr>
<td align="right">1.23</td>
<td align="right">543.77</td>
<td align="right">23.45</td>
<td align="right">8756.00</td>
</tr>
</table>
-- Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
- Next message: tom: "Align help for two seperate php files"
- Previous message: Douglas F.: "Re: headers already sent ..."
- In reply to: Glenn: "Re: Zero Filling Integer"
- Next in thread: Glenn: "Re: Zero Filling Integer"
- Reply: Glenn: "Re: Zero Filling Integer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|