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

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

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

    カレンダー 11−3

    <?php require("11_03_date_b.php"); ?>
    <!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">
    <title>カレンダーを表示する</title></head>
    <body><div class="file2">
    <?php cal();?>    <!--ここがPHP//-->
    </div></body></html>

    カレンダー 11−3 カレンダーの部分

    <style type="text/css">
    <!--
    .head_sun { text-align:center;background-color:#ffdddd;font-size:10px;color:black;padding:2px }
    .head_sat { text-align:center;background-color:#ddddff;font-size:10px;color:black;padding:2px }
    .head_othr { text-align:center;background-color:#ffffdd;font-size:10px;color:black;padding:2px }
    .sun_today { text-align:center;background-color:#bbbbff;font-size:10px;color:black;padding:2px }
    .sun_past { text-align:center;background-color:#ddffdd;font-size:10px;color:red;padding:2px }
    .sun_future { text-align:center;background-color:#ffffff;font-size:10px;color:red;padding:2px }
    .sat_today { text-align:center;background-color:#bbbbff;font-size:10px;color:blue;padding:2px }
    .sat_past { text-align:center;background-color:#ddffdd;font-size:10px;color:blue;padding:2px }
    .sat_future { text-align:center;background-color:#ffffff;font-size:10px;color:blue;padding:2px }
    .othr_today { text-align:center;background-color:#bbbbff;font-size:10px;color:black;padding:2px }
    .othr_past { text-align:center;background-color:#ddffdd;font-size:10px;color:black;padding:2px }
    .othr_future { text-align:center;background-color:#ffffff;font-size:10px;color:black;padding:2px }
    //-->
    </style>

    <?php
    error_reporting(1);
    function cal(){
      $year = date(Y);
      $month = date(n);
      echo "<table border ='0' bgcolor='#e0e0e0' cellspacing='2'><tr>¥n";
      echo "<td colspan='7' bgcolor='white' align='center'><font size=3>".$year."年".$month."月</font></td><tr>";
      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";
      }

      for( $day = 1 ; checkdate( $month, $day, $year ) ; $day++ ){    /*日付記述、最後に1を足すので32になるそれでも曜日を返す*/
          $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>";
    }

    ?>
    2019/3
    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
    31       


     フォクすけ©2006 Mozilla Japan



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

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