[PHP] Re: Having trouble formatting width using printf() and default spaces

2004-03-30 Thread Jason Barnett
David Scott wrote:

I'm using a for() loop to generate random die rolls. I'd like the 
numbers to be formatted in a grid.
In a grid... like an HTML table?  You could something like:
$row = 20;
$col = 5;
echo 'table';
for ($i = 1; $i  $row; $i++) {
echo 'tr';
for ($j = 1; $j  $col; $j++) {
echo 'td'.rand(1, $sides).'/td';
}
echo '/tr';
}
echo '/table';
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


[PHP] Re: Having trouble formatting width using printf() and default spaces

2004-03-30 Thread David Scott
I tried your method and it's a nice variation, though it leaves me with 
two issues:

1. I'd like the numbers to be right-aligned.
2. I'd still like to understand why the default padding of spaces isn't 
working for printf(). If I could get printf() to pad with spaces, it 
would be exactly what I'm after.

Jason Barnett wrote:
David Scott wrote:

I'm using a for() loop to generate random die rolls. I'd like the 
numbers to be formatted in a grid.


In a grid... like an HTML table?  You could something like:
$row = 20;
$col = 5;
echo 'table';
for ($i = 1; $i  $row; $i++) {
echo 'tr';
for ($j = 1; $j  $col; $j++) {
echo 'td'.rand(1, $sides).'/td';
}
echo '/tr';
}
echo '/table';
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


[PHP] Re: Having trouble formatting width using printf() and default spaces

2004-03-30 Thread David Robley
[EMAIL PROTECTED] (David Scott) wrote in 
news:[EMAIL PROTECTED]:

 I tried your method and it's a nice variation, though it leaves me with 
 two issues:
 
 1. I'd like the numbers to be right-aligned.
 2. I'd still like to understand why the default padding of spaces isn't 
 working for printf(). If I could get printf() to pad with spaces, it 
 would be exactly what I'm after.
 
 Jason Barnett wrote:
 David Scott wrote:
 
 I'm using a for() loop to generate random die rolls. I'd like the 
 numbers to be formatted in a grid. 
 
 
 In a grid... like an HTML table?  You could something like:
 $row = 20;
 $col = 5;
 echo 'table';
 for ($i = 1; $i  $row; $i++) {
 echo 'tr';
 for ($j = 1; $j  $col; $j++) {
 echo 'td'.rand(1, $sides).'/td'; }
 echo '/tr';
 }
 echo '/table';
 

 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? 
 

Don't forget if you are looking at the output in a browser, the browser 
will ignore extraneous white space unless you either surround the text with 
PRE tags or use nbsp; instead of a 'standard' spcae character.

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