위토즈 - 개발자프로그램판매공간

정보공유

[PHP] 달력 함수.

function.calendar.php
[code]
<?
//** 한달의 총 날짜 계산 함수
function Month_Day($i_month,$i_year)
{
$day = 1;
while(checkdate($i_month, $day, $i_year))
{
$day++;
}
$day--;
return $day;
}


function setCals($year, $month)
{

$time = time(); //** 1일이후로 변경할경우 time()+60*60*24;

//** 오늘 날짜를 년월일별로 구하기
$today_year = date("Y",$time);
$today_month = date("n",$time);
$today_day = date("j",$time);

//** 선택한 월의 총 일수를 구함.
$total_day = Month_Day($month, $year);

//** 선택한 월의 1일의 요일을 구함. 일요일은 0.
$first_day = date(w, mktime(0,0,0,$month,1,$year));

//** 지난달과 다음달을 보는 루틴
$year_p = $year-1;
$year_n = $year+1;

if($month == 1)
{
$year_prev = $year_p;
$year_next = $year;
$month_prev = 12;
$month_next = $month+1;
}
else if($month == 12)
{
$year_prev = $year;
$year_next = $year_n;
$month_prev = $month-1;
$month_next = 1;
}
else if($month != 1 && $month != 12)
{
$year_prev = $year;
$year_next = $year;
$month_prev = $month-1;
$month_next = $month+1;
}

//** count는 <tr>태그를 넘기기위한 변수. 변수값이 7이되면 <tr>태그를 삽입한다.
$count = 0;
$i = 1;
$html = "";


$html = "
<tr height=30>
<td colspan=7 align=center>
". $year ."년 ". $month ."월
</td>
</tr>
<tr>
<td class=bgsun>일</td>
<td class=bgweek>월</td>
<td class=bgweek>화</td>
<td class=bgweek>수</td>
<td class=bgweek>목</td>
<td class=bgweek>금</td>
<td class=bgsat>토</td>
</tr>";

//첫번째 주에서 빈칸을 1일전까지 빈칸을 삽입
for($i = 0; $i < $first_day; $i++)
{
$html .= "<td class=valid>&nbsp;</td>";
$count++;
}


//===========날짜를 테이블에 표시=================//
for($day = 1; $day <= $total_day; $day++)
{
$count++;

//** 오늘 표시
if($day == $today_day && $month == $today_month && $year == $today_year)
{
$bg_class = "today";
}
else {//** 오늘이 아니면...

if ($count == 1) //** 일요일
{
$bg_class = "bgsun";
}
elseif ($count == 7) //** 토요일
{
$bg_class = "bgsat";
}
else //** 평일
{
$bg_class = "bgweek";
}

}//** 오늘이 아니면...끝


$vDate = $year ."-". substr( "0". $month,-2) ."-". substr( "0". $day,-2); //** 표시 날짜.
$tDate = $today_year ."-". substr( "0". $today_month,-2) ."-". substr( "0". $today_day,-2); //** 오늘 날짜.


$html .= "<td class='". $bg_class ."' id='rev_". $vDate ."'>". $day ."</td>";



if($count==7) //** 토요일이 되면 줄바꾸기 위한 <tr>태그 삽입을 위한 식
{
$html .= "</tr>";
if($day != $total_day){$html .= "<tr>"; $count = 0;}
}
}

//** 선택한 월의 마지막날 이후의 빈테이블 삽입
for($day++; $total_day < $day && $count < 7; )
{
$count++;
$html .= "<td class=valid>&nbsp;</td>";
if($count == 7){ $html .= "</tr>";}
}


return $html;
}
?>
[/code]



test.php
[code]
<?
include_once("function.calendar.php");
?>

<style type="text/css">
  table.calgroup {margin:10px 0 20px;}
  table.calgroup td {height:22px;text-align: center;}
  table.calgroup td.bgsun {color: red;}
  table.calgroup td.bgsat {color: blue;}
  table.calgroup td.bgweek {color: #000;}
  table.calgroup td.today {color: #000;font-weight:bold}
</style>
<table width="400" cellSpacing=0 cellPadding=0 border=0 class="calgroup" align="center">
<?
$time = date("Ymd");
$year = substr($time,0,4);
$month = substr($time,4,2);
echo setCals($year, $month);
?>
</table>
[/code]
정보공유
Total 74건 5 페이지
번호 제목 글쓴이 날짜 조회
14 cURL을 이용한 웹페이지 가져오기 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-20 35307
13 2차원 배열 정렬 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-18 29295
12 cURL 모듈 사용가능여부 판단. 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-15 30686
11 정규식 참고 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-27 29380
10 메일주소 정규식 체크 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-25 29591
9 유니크 한 일련번호 생성하기. 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-17 32434
8 원하는 자릿수 만큼 문자열 생성처리 함수. sprintf 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-11 28346
7 Simple Microphone Recorder 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-26 29734
6 즐겨쓰는 php db 연결문 (접속 - 해제) 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-24 31831
열람중 달력 함수. 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-24 28613
4 GD 를 이용한 그래프 만들기 SAMPLE 2 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-18 28430
3 GD 를 이용한 그래프 만들기 SAMPLE 1 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-18 29558
2 Minify 를 이용한 JavaScript, CSS 압축 전송 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-09 41086
1 php 를 asp 로 db연결방법 파일업로드 최고관리자쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-07 35876