Hopsel: zahlenformat auf 2 stellen festlegen

Beitrag lesen

Hi Jan!

Könnte ich $i vom aktuellen einstelligen zahlenformat 1-9..10 usw. auch auf das das format 01-09 umstellen?

Ja, mit printf oder sprintf.

$monat= date("m");

Wozu das?

$jahr= date("y");
switch($_GET[action]) {
case "01": $monat1="January"; break;
case "02": $monat1="February"; break;
case "03": $monat1="March"; break;
case "04": $monat1="April"; break;
case "05": $monat1="May"; break;
case "06": $monat1="June"; break;
case "07": $monat1="July"; break;
case "08": $monat1="August"; break;
case "09": $monat1="September"; break;
case "10": $monat1="October"; break;
case "11": $monat1="November"; break;
case "12": $monat1="December"; break;

Was passiert, wenn etwas anderes per GET übergeben wird?

}
if ( file_exists("$jahr/$monat1/01.ip.txt") ) {echo "<b>01</b>";}
if ( file_exists("$jahr/$monat1/02.ip.txt") ) {echo "<b>02</b>";}
if ( file_exists("$jahr/$monat1/03.ip.txt") ) {echo "<b>02</b>";}
if ( file_exists("$jahr/$monat1/04.ip.txt") ) {echo "<b>04</b>";}
if ( file_exists("$jahr/$monat1/05.ip.txt") ) {echo "<b>05</b>";}
if ( file_exists("$jahr/$monat1/06.ip.txt") ) {echo "<b>06</b>";}
if ( file_exists("$jahr/$monat1/07.ip.txt") ) {echo "<b>07</b>";}
if ( file_exists("$jahr/$monat1/08.ip.txt") ) {echo "<b>08</b>";}
if ( file_exists("$jahr/$monat1/09.ip.txt") ) {echo "<b>09</b>";}
for ($i=0;$i<=31;$i++) {
if ( file_exists("$jahr/$monat1/$i.ip.txt") ) {echo "<b>$i</b>";}
}

Und was bezweckst du hiermit? Erst lässt du von 01 bis 09 ausgeben und dann nochmal von 0 bis 31.
Wenn du überlegst, wirst du auch darauf kommen, warum es funktioniert und warum $i in der for-Schleife nicht mit 0 initialisiert zu werden braucht.

MfG H☼psel

--
"It's amazing I won. I was running against peace, prosperity, and incumbency."
George W. Bush speaking to Swedish Prime Minister unaware a live television camera was still rolling, June 14, 2001
Selfcode: ie:% fl:( br:> va:) ls:& fo:) rl:? n4:& ss:| de:] js:| ch:? sh:( mo:) zu:)