작은 달력 표시하기

//* calendar 용..

//표시하고자 하는 월 값 초기화
$cur_date = isset($cur_date) ? strtotime($cur_date) : time();

//요일의 시작을 설정(일요일이면 0, 월요일이면 1)
$start_dayofweak = 0;//0-sunday , 1-monday

//달력정보 : 달력에서 표시하는 첫날과 마지막날의 정보
$calendar = getCalendarInfo($cur_date,$start_dayofweak);
$day_term = 60*60*24;

//전월과 다음월 : 링크위해 사용
$before_cur_date = date(“Y-m-d”,mktime(0,0,0,date(“m”,$cur_date)-1,1,date(“Y”,$cur_date)));
$next_cur_date = date(“Y-m-d”,mktime(0,0,0,date(“m”,$cur_date)+1,1,date(“Y”,$cur_date)));

echo ”

“;
for($i = 0;$i<7;$i++) echo "

“;
echo “

“;

$disp_type = 0; //0:no month, 1:with month
$_disp_month = 0;

$_cnt = 0;
while(1){
//표시할 날짜
$display_date = intval($calendar[startdate]+$_cnt*$day_term);

//색깔
switch(strftime(“%w”,$display_date)){
case 0: //sun
$fontstyle = ““;break;
case 6://sat
$fontstyle = ““;break;
default:
$fontstyle = ““;break;
}
if(date(“m”,$cur_date)!=date(“m”,$display_date))
$fontstyle = ““;

if(strtotime(date(“Y-m-d”)) == $display_date) $fontstyle.=”“;

//출력
if(!$_disp_month):
$date_str = date(“m/d”,$display_date);
$_disp_month = true;
else:
if(intval(date(“d”,$display_date)) == 1) {
$date_str = date(“m/d”,$display_date);
} else {
$date_str = date(“d”,$display_date);
}
endif;

echo sprintf(“%s

%s”,(($_cnt%7 == 0) ? “

” : “”),$fontstyle,$date_str,((!$_cnt%7 == 6) ? “

” : “”));

if($display_date==$calendar[enddate]) break;

$_cnt++;
}

//* 해당월 달력정보
function getCalendarInfo($date,$start_dayofweak = 0){

$_date = is_numeric($date) ? $date : strtotime($date);

$info = array();
//그달의 첫날
$info[firstdate] = mktime(0,0,0,date(“m”,$_date),1,date(“Y”,$_date));
//그달의 마지막날
$info[lastdate] = mktime(0,0,0,date(“m”,$_date)+1,0,date(“Y”,$_date));
//달력시작일
$info[startdate] = $info[firstdate] + 60*60*24*intval($start_dayofweak-strftime(“%w”,$info[firstdate]));
//달력종료일
$info[enddate] = $info[lastdate] + 60*60*24*intval($start_dayofweak-strftime(“%w”,$info[lastdate])+6);
return $info;
}
?>

“.strftime(‘%B, %Y’,$cur_date).”
<  
>
“.substr(date(“l”,intval($calendar[startdate]+$i*$day_term)),0,1).”
%s%s