基礎から解る!PHP入門講座 プログラム入門に最適な言語、PHPを学ぼう

基礎から解る!PHP入門講座

プログラム入門に最適な言語、PHPを学ぼう      

    カレンダー 11−2

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="ja"><head>
    <meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <link rel="stylesheet" href="./style.css">
    <style type="text/css">
    <!--
    .head_sun { text-align:center;background-color:#ffdddd;font-size:18px;color:black;font-weight:bold;padding:5px }
    .head_sat { text-align:center;background-color:#ddddff;font-size:18px;color:black;font-weight:bold;padding:5px }
    .head_othr { text-align:center;background-color:#ffffdd;font-size:18px;color:black;font-weight:bold;padding:5px }
    .sun_today { text-align:center;background-color:#4444ff;font-size:18px;color:white;font-weight:bold;padding:5px }
    .sun_past { text-align:center;background-color:#ccccff;font-size:18px;color:red;font-weight:bold;padding:5px }
    .sun_future { text-align:center;background-color:nine;font-size:18px;color:red;font-weight:bold;padding:5px }
    .sat_today { text-align:center;background-color:#4444ff;font-size:18px;color:white;font-weight:bold;padding:5px }
    .sat_past { text-align:center;background-color:#ccccff;font-size:18px;color:blue;font-weight:bold;padding:5px }
    .sat_future { text-align:center;background-color:none;font-size:18px;color:blue;font-weight:bold;padding:5px }
    .othr_today { text-align:center;background-color:#4444ff;font-size:18px;color:white;font-weight:bold;padding:5px }
    .othr_past { text-align:center;background-color:#ccccff;font-size:18px;color:black;font-weight:bold;padding:5px }
    .othr_future { text-align:center;background-color:none;font-size:18px;color:black;font-weight:bold;padding:5px }
    //-->
    </style>

    <title>カレンダー</title></head>
    <body><div class="file2">
    1970年から2037年のカレンダーを見ることができます。
    <form action="11_02_date.php" method="post">
    <select name="year">
    <?php
    error_reporting(1);
    $cnt = 1970;
    while ($cnt < 2038){
      if($cnt == date(Y)){
      echo "<option value='$cnt' selected>$cnt</option>";
      } else {
      echo "<option value='$cnt'>$cnt</option>";
      }
    $cnt++;
    }
    ?>

    </select><select name="month">
    <?php
    $cnt = 1;
    while ($cnt < 13){
      if($cnt == date(n)){
      echo "<option value='$cnt' selected>$cnt</option>";
      } else {
      echo "<option value='$cnt'>$cnt</option>";
      }
    $cnt++;
    }
    ?>

    </select><input type="submit" value="作成!"></form>
    <?php
      $year = $_POST['year'];
      $month = $_POST['month'];

    if($year == null){
      $year = date(Y);
    }

    if($month == null){
      $month = date(n);
    }
    /*-------------------------------------------------------*/
    echo "<font size=5><b>$year 年 $month 月</b></font>";
    echo "<table border ='1'><tr>¥n";
    echo "<td class='head_sun'>日</td>¥n";
    echo "<td class='head_othr'>月</td>¥n";
    echo "<td class='head_othr'>火</td>¥n";
    echo "<td class='head_othr'>水</td>¥n";
    echo "<td class='head_othr'>木</td>¥n";
    echo "<td class='head_othr'>金</td>¥n";
    echo "<td class='head_sat'>土</td></tr>¥n";

    $wtop = date(w,mktime(0,0,0,$month,1,$year)) ;  /*指定月1日の曜日*/

    for($dot1 = 0 ; $dot1 < $wtop ; $dot1++){    /*日付が始まる前の空白*/  
      echo "<td align='center'>・</td>¥n";
    }
    /*-----------------------------日付記述、最後に1を足すので32になるそれでも曜日を返す*/
    for( $day = 1 ; checkdate( $month, $day, $year ) ; $day++ ){
        $todaystamp = mktime(0,0,0,date(m),date(j),date(Y));
        $daystamp = mktime(0,0,0,$month,$day,$year);

      if(($day+$wtop)%7 == 1){
        if($todaystamp == $daystamp){
          echo "<tr>¥n<td class='sun_today'>$day</td>¥n";    /*日曜日*/
        } else if($todaystamp > $daystamp) {
          echo "<tr>¥n<td class='sun_past'>$day</td>¥n";    
        } else {
          echo "<tr>¥n<td class='sun_future'>$day</td>¥n";    
        }
      } else if(($day+$wtop)%7 == 0){
        if($todaystamp == $daystamp){
          echo "<td class='sat_today'>$day</td>¥n</tr>¥n";    /*土曜日*/
        } else if($todaystamp > $daystamp) {
          echo "<td class='sat_past'>$day</td>¥n</tr>¥n";    
        } else {
          echo "<td class='sat_future'>$day</td>¥n</tr>¥n";    
        }
      } else {
        if($todaystamp == $daystamp){
          echo "<td class='othr_today'>$day</td>¥n";      /*その他*/
        } else if($todaystamp > $daystamp) {
          echo "<td class='othr_past'>$day</td>¥n";    
        } else {
          echo "<td class='othr_future'>$day</td>¥n";          
        }
      }
    }
    /*--------------------------------------------------------------*/
    $wend = date(w,mktime(0,0,0,$month,$day,$year)) ;  //指定月最終日の曜日$dayは32になっている
    if($wend !=0){  //  もし32が日曜日すなわち0ならそれで終了
      for($dot2 =0 ; $dot2 < 7-$wend ;$dot2++){        /*0以外は・が必要*/
        echo "<td align='center'>・</td>";
      }
    }
    echo "</tr></table>";

    ?>

    </div></body></html>
    2019/11
    SUN MON TUE WED THU FRI SAT
              1 2
    3 4 5 6 7 8 9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30


     フォクすけ©2006 Mozilla Japan



    制作:基礎から解るPHP入門講座 代表:FREEZE

    Copyright © 2005/2/28 flzPHP.All Rights Riserved