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
mrvanjohnson
Forum Contributor
Posts: 137 Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA
Post
by mrvanjohnson » Thu Oct 02, 2003 10:23 pm
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++) {
if ($m == date("n")){
print "<b>$m</b><br>";
}else{
print $m. "<br>";
}
}
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..
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Oct 02, 2003 10:32 pm
http://de3.php.net/date m Numeric representation of a month, with leading zeros
...
n Numeric representation of a month, without leading zeros
mrvanjohnson
Forum Contributor
Posts: 137 Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA
Post
by mrvanjohnson » Thu Oct 02, 2003 10:35 pm
Not doing date just need the number formated.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Oct 02, 2003 10:37 pm
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);
}
}
?>
mrvanjohnson
Forum Contributor
Posts: 137 Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA
Post
by mrvanjohnson » Thu Oct 02, 2003 10:44 pm
Thanks volka
You a scholar and a gentleman!!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Oct 02, 2003 11:43 pm
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?