짱

[PHP 기초] 달력 만들기

· 2004-12-11 (토) 23:59:28 · 8154 · 2
이번달 달력(양력)을 표시하는 소스입니다. 조금만 응용하면 여러가지 모양이 나올 수 있겠죠!

<?php
// 지정한 년,월의 총 일수를 구한다.
function cal_days_in_month($month, $year) {
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
?>
<?php
$date_month = date("m"); //오늘이 속한 월(1,2,3...12)
$date_year = date("Y"); //오늘이 속한 년(...2003,2004,2005...)
$t_days = cal_days_in_month($date_month, $date_year); //지정한 년,월의 총 일수(28,29,30,31)
$day = date("w", mktime(0, 0, 0, $date_month, 1, $date_year)); //0(일요일)부터 6(토요일)
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>달력</title>
<style type=text/css>
td { font-size:12px; font-family:돋움체; color:#7D7D7D; line-height:1.2; }
th { font-size:13px; font-family:돋움체; color:#000000; line-height:1.5; }
.today { font-size:12px; font-family:돋움체; color:#000000; background:#C4E1FF line-height:1.2; }
</style>
</head>
<body bgcolor=#FFFFFF>

<table border="0" bgcolor="#F2F2F2" cellpadding="2" cellspacing="2">
<tr><th colspan="7"><?php echo $date_year."년 ".$date_month."월"; ?></th></tr>
<tr bgcolor="#C0C0C0"><th><font color="#FF0000">일</font></th><th>월</th><th>화</th><th>수</th>
<th>목</th><th>금</th><th><font color="#0000FF">토</font></th></tr>
<?php
for ($i = 0; $i <= $t_days; $i++) {
if ($day > 6) {
echo "</tr>\n<tr>\n";
$day = 0;
}

if ($i == date("j")) { ?>
<td align="right" class="today"><?php echo $i; $day++; echo "</td>\n";
}
else if ($i > 0) { ?>
<td align="right"><?php echo $i; $day++; echo "</td>\n";
}
else if ($day > 0) { ?>
<tr><td colspan="<?php echo $day; ?>"><?php echo "</td>\n";
}

if ($i == $t_days && $day < 6) { ?>
<td colspan="<?php echo 7 - $day; ?>"><?php echo "</td>\n</tr>\n";
}
}
?>
</table>
</body>
</html><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
|

댓글 2개

line4

return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);} 여서 에러가 나는 이유가 궁금 합니다.. 원인을 못찾게다는.
2007-11-14 (수) 18:18:08
wrappin 님과 동감이라는.. ㅡ,.ㅡ
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
06-05-31 조회 4,124
06-05-31 조회 4,356
06-05-30 조회 3,384
06-05-26 조회 4,484
06-05-26 조회 4,770
06-05-15 조회 4,503
06-05-14 조회 5,736
06-05-12 조회 3,172
06-05-11 조회 4,583
06-05-11 조회 2,724
06-05-11 조회 2,841
06-05-11 조회 2,560
06-05-11 조회 2,826
06-05-11 조회 2,415
06-05-11 조회 2,955
06-05-10 조회 3,442
06-05-09 조회 8,117
06-05-09 조회 3,336
06-05-09 조회 3,438
06-05-07 조회 3,919
06-05-07 조회 3,017
06-05-07 조회 3,645
06-04-29 조회 3,669
06-04-28 조회 4,562
06-04-25 조회 3,467
06-04-25 조회 3,753
06-04-25 조회 3,561
06-04-22 조회 3,184
06-04-13 조회 4,508
06-04-13 조회 4,375
06-04-09 조회 3,344
06-03-30 조회 4,769
06-03-24 조회 3,597
06-03-21 조회 3,589
06-03-15 조회 4,614
06-03-11 조회 3,222
06-03-03 조회 3,465
06-02-22 조회 3,272
06-01-27 조회 3,429
06-01-05 조회 3,515
05-12-30 조회 3,361
05-12-29 조회 3,850
bbbking
05-10-22 조회 5,315
05-08-19 조회 5,520
05-08-16 조회 3,548
05-07-13 조회 4,739
05-07-11 조회 3,888
05-07-01 조회 3,487
05-07-01 조회 3,093
05-07-01 조회 3,554
bbbking
05-06-30 조회 6,267
bbbking
05-06-16 조회 6,838
05-04-04 조회 6,373
05-03-13 조회 3,258
05-03-13 조회 2,331
05-03-13 조회 2,492
04-12-16 조회 5,793
04-11-29 조회 4,163
04-11-28 조회 3,959
04-11-28 조회 3,156
04-11-28 조회 3,805
04-11-28 조회 3,577
04-11-24 조회 3,012
04-11-12 조회 2,972
04-08-24 조회 5,280
04-08-10 조회 4,490
04-08-10 조회 5,084