[php] php 달력 만들기 – 아랑

<?

// 해당 연, 월의 일수를 계산한다. t -> 월의 총일수

function getTotalDays ($month, $year) {

        $date = date (“t”,mktime(0,0,1,$month,1,$year));

        return $date;

}

/*

해당 연월의 달력을 출력한다. w -> 요일

date 함수를 사용하여 함수의 인자로 년/ 월이 입력되고 월의 1일을 기준으로 달력의 1일이 위치하는 곳을 지정하게 된다.

*/

function showCalendar ($year, $month, $totalDays) {

        $firstDay = date (“w”, mktime(0,0,0,$month,1,$year));

        echo (”

<table width=350 border=0 cellspacing=0 cellpadding=1> <tr><td bgcolor=#666666>

<table width=350 border=0 cellspacing=1 cellpadding=10> <tr><td width=350 colspan=7 bgcolor=#000000 align=center><font color=#cccccc> $year 년 $month 월 달력</font></td></tr> <tr>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 일 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 월 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 화 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 수 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 목 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 금 </font></td>

        <td width=50 align=center bgcolor=#000000><font color=#cccccc> 토 </font></td> </tr> <tr>

“);

$col=0;

// for 구문으로 해당 월의 첫번째 요일이 무슨 요일인지를 확인  

for ($i=0; $i < $firstDay; $i++) {

        echo (“<td align=center bgcolor=#000000> </td>\\n”);

        $col++;

}

for ($j=1; $j <= $totalDays; $j++) {

        if ($col==0) {

        echo “<td align=center bgcolor=#000000><font color=red> $j </font></td>”;

  $col++;

        } else if ( $col==6) {

  echo “<td align=center bgcolor=#000000><font color=lightblue> $j </font></td>”;

  $col++;

        } else {

        echo (“<td align=center bgcolor=#000000><font color=#cccccc> $j </font></td>”);

        $col++;

        }

        if ($col == 7) {

        echo (“</tr>”);

                if ($j != $totalDays) {

                echo (“<tr>\\n”);

                }

                $col=0;

        }

}

while ($col > 0 && $col < 7 ) {

        echo (“<td align=center bgcolor=#000000> </td>\\n”);

        $col++;

}

echo (” </tr></table> <td></tr></table> \\n”);

}

?>

<html>

<head>

   <title>PHP로 구현하는 달력프로그램</title>

   <style type=”text/css”>

   <!–

      BODY,TR,TH,TD {

         font-family: “굴림”;

         font-size: 9pt;

      }

   //–>

   </style>

</head>

<body bgColor=”#FFFFFF”>

<form method=post action=calendar.php>

<input type=text size=4 name=year> 년 <input type=text size=2 name=month> 월   <input type=submit value=”출력”> </form>

<?

if ( $year and $month ) {

$totalDays = getTotalDays($month,$year); showCalendar($year,$month,$totalDays);

} else {

$year = 2005;

$month = 5;

$totalDays = getTotalDays($month,$year); showCalendar($year,$month,$totalDays);

}

?>

</body>

</html>

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

2 Responses

  1. 2022년 6월 19일

    1contiguity

  2. 2023년 1월 26일

    1shipment

페이스북/트위트/구글 계정으로 댓글 가능합니다.