Page 1 of 1

Change 1 to 01

Posted: Thu Oct 02, 2003 10:23 pm
by mrvanjohnson
Alright, just when I think I have a good understanding of PHP I forget the simple things. I know this is easy and has been addressed he but I did a search and was unable to find the posting.

He it is, I have a simple for call

Code: Select all

for ($m = 1; $m <= 12; $m++) &#123;
        if ($m == date("n"))&#123;
                print "<b>$m</b><br>";
                &#125;else&#123;
                print $m. "<br>";
             &#125;
         &#125;
but instead of it printing the numbers 1 2 3 4 5 etc ... I would like it to print 01 02 03 04 05 etc ...

Help please..

Posted: Thu Oct 02, 2003 10:32 pm
by volka
http://de3.php.net/date
m Numeric representation of a month, with leading zeros
...
n Numeric representation of a month, without leading zeros

Posted: Thu Oct 02, 2003 10:35 pm
by mrvanjohnson
Not doing date just need the number formated.

Posted: Thu Oct 02, 2003 10:37 pm
by volka
ah right, my fault ;)

Code: Select all

<?php
for ($m = 1; $m <= 12; $m++) {
	if ($m == date('n')) {
		printf ('<b>%02d</b><br />', $m);
	}else{
		printf ('%02d<br />', $m);
	}
 } 
?>

Posted: Thu Oct 02, 2003 10:44 pm
by mrvanjohnson
Thanks volka
You a scholar and a gentleman!!
:-)

Posted: Thu Oct 02, 2003 11:43 pm
by volka
seems like I hear/read this once a year.
Next time I'll start to believe it
but then who will scare the beginners to death? :twisted: