Change 1 to 01

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Change 1 to 01

Post 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..
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Not doing date just need the number formated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
	}
 } 
?>
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Thanks volka
You a scholar and a gentleman!!
:-)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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:
Post Reply