Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2004032

RE: [PHP] Having trouble formatting width using printf() and defa ult spaces From: Martin Towell (martin.towell <email protected>)
Date: 03/31/04

spaces in HTML are collapsed to a single space, that why you only see the
numbers seperated by a single space.

doesn't look like you can use printf() directly to use &nbsp; as the space
character, however, you can use sprintf() and str_replace() together to do
the same effect.

Try this:
     echo str_replace(" ", "&nbsp;", sprintf("%10u", rand(1,$sides)));

Martin

> -----Original Message-----
> From: David Scott [mailto:dscott <email protected>]
> Sent: Wednesday, 31 March 2004 8:01 AM
> To: php-general <email protected>
> Subject: [PHP] Having trouble formatting width using printf() and
> default spaces
>
>
> I'm using a for() loop to generate random die rolls. I'd like the
> numbers to be formatted in a grid.
>
> for ($i = 0; $i < 100; $i++) {
> if (!($i % 5)) {
> print("<br />");
> }
> printf("%'.10u", rand(1,$sides));
> }
>
> Currently, I'm padding with '.', but I'd like to pad with the default
> spaces.
>
> For example, printf("%10u", rand(1,$sides)); Except the
> numbers end up like,
>
> 7 10 14 19 3
> 4 6 16 13 2
> etc.
>
> Why is it that when I leave out the padding character, the
> output isn't
> padded?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> __________ Information from NOD32 1.617 (20040206) __________
>
> This message was checked by NOD32 for Exchange e-mail monitor.
> http://www.nod32.com
>
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php