PHP로 만든 달력

2015.10.27 13:24

졸리운_곰 조회 수:118

PHP로 만든 달력

2072967698_b8cde66a_dev1.jpg

 

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

필요하신 분은 쓰세요

매개변수로 toYear로 년도와 toMonth로 월을 넘기면 적용이 됩니다 ^^*

<?
/******************************
달력
******************************/

/********** 사용자 설정값 **********/
$startYear        = 2007;
$endYear        = date( "Y" ) + 4;

/********** 입력값 **********/
$year            = ( $_GET['toYear'] )? $_GET['toYear'] : date( "Y" );
$month            = ( $_GET['toMonth'] )? $_GET['toMonth'] : date( "m" );
$doms            = array( "일", "월", "화", "수", "목", "금", "토" );

/********** 계산값 **********/
$mktime            = mktime( 0, 0, 0, $month, 1, $year );      // 입력된 값으로 년-월-01을 만든다
$days            = date( "t", $mktime );                        // 현재의 year와 month로 현재 달의 일수 구해오기
$startDay        = date( "w", $mktime );                        // 시작요일 알아내기

// 지난달 일수 구하기
$prevDayCount    = date( "t", mktime( 0, 0, 0, $month, 0, $year ) ) - $startDay + 1;

$nowDayCount    = 1;                                            // 이번달 일자 카운팅
$nextDayCount    = 1;                                          // 다음달 일자 카운팅

// 이전, 다음 만들기
$prevYear        = ( $month == 1 )? ( $year - 1 ) : $year;
$prevMonth        = ( $month == 1 )? 12 : ( $month - 1 );
$nextYear        = ( $month == 12 )? ( $year + 1 ) : $year;
$nextMonth        = ( $month == 12 )? 1 : ( $month + 1 );

// 출력행 계산
$setRows = ceil( ( $startDay + $days ) / 7 );
?>

<!---------- 달력 출력 ---------->

<center>

<table style="border-collapse:collapse;">
    <form method="get">
    <tr>
        <td style="padding:10;border-width:1;border-style:solid;">
        <select name="toYear" onchange="submit();">
        <? for( $i = $startYear; $i < $endYear; $i++ ) { ?>
        <option value="<?=$i?>" <?=($i==$year)?"selected":""?>><?=$i?></option>
        <? } ?>
        </select>년
        <select name="toMonth" onchange="submit();">
        <? for( $i = 1; $i <= 12; $i++ ) { ?>
        <option value="<?=$i?>" <?=($i==$month)?"selected":""?>><?=$i?></option>
        <? } ?>
        </select>월
        </td>
    </tr>
    </form>
</table>

<br>

<table style="border-collapse:collapse;">
    <tr>
        <td style="padding:10;border-width:1;border-style:solid;">
        <input type="button" onclick="location.href='<?=$_SERVER['PHP_SELF']?>?toYear=<?=$prevYear?>&toMonth=<?=$prevMonth?>'" value=" << ">
        <?=$year?>년 <?=$month?>월
        <input type="button" onclick="location.href='<?=$_SERVER['PHP_SELF']?>?toYear=<?=$nextYear?>&toMonth=<?=$nextMonth?>'" value=" >> ">
        </td>
    </tr>
</table>

<br>

<table cellpadding=0 cellspacing=0 style="border-collapse:collapse;">

    <tr>
        <? for( $i = 0; $i < count( $doms ); $i++ ) { ?>
        <td align="center" style="padding:6;border-width:1;border-style:solid;"><?=$doms[$i]?>요일</td>
        <? } ?>
    </tr>

    <? for( $rows = 0; $rows < $setRows; $rows++ ) { ?>
    <tr>
        <?
        for( $cols = 0; $cols < 7; $cols++ )
        {
            // 셀 인덱스 만들자
            $cellIndex    = ( 7 * $rows ) + $cols;
            ?>

            <?
            // 이번달이라면
            if ( $startDay <= $cellIndex && $nowDayCount <= $days ) { ?>
            <td align="center" style="padding:6;border-width:1;border-style:solid;">
                <? if ( date( "w", mktime( 0, 0, 0, $month, $nowDayCount, $year ) ) == 6 ) { ?>
                <b><font color="blue"><?=$nowDayCount++?></font></b>
               
                <? } else if ( date( "w", mktime( 0, 0, 0, $month, $nowDayCount, $year ) ) == 0 ) { ?>
                <b><font color="red"><?=$nowDayCount++?></font></b>
               
                <? } else { ?>
                <b><?=$nowDayCount++?></b>
                <? } ?>
            </td>
           
            <?
            // 이전달이라면
            } else if ( $cellIndex < $startDay ) { ?>
            <td align="center" style="padding:6;border-width:1;border-style:solid;">
            <font color="gray"><b><?=$prevDayCount++?></b></font>
            </td>
           
            <?
            // 다음달 이라면
            } else if ( $cellIndex >= $days ) { ?>
            <td align="center" style="padding:6;border-width:1;border-style:solid;">
            <font color="gray"><b><?=$nextDayCount++?></b></font>
            </td>
            <? }
        }
        ?>
    </tr>
    <? } ?>

</center>

</table>

 

 

[출처] http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=65572

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
49 An inference engine for PHP : php로 prolog 구현 file 졸리운_곰 2017.01.06 49
48 Steps to configure PHP Cron Jobs – Godaddy file 졸리운_곰 2016.12.13 103
47 Creating a simple REST API in PHP 졸리운_곰 2016.11.28 53
46 AngularJS CRUD: Example Using MySQLi Database file 졸리운_곰 2016.11.20 99
45 HTML form 태그, input type 종류 file 졸리운_곰 2016.10.09 358
44 php 와 python 연동 , php 페이지에서 python 사용 졸리운_곰 2016.10.05 97
43 Big data in PHP file 졸리운_곰 2016.09.27 64
42 php에서 Access (엑세스) mdb (accdb) 파일에 연결 file 졸리운_곰 2016.08.11 1419
41 SQLite 소개 졸리운_곰 2016.08.11 872
40 SQLite 와 php 의 연동 졸리운_곰 2016.08.11 824
39 wp 워드프레스 플러그인 만들기 pdf file 졸리운_곰 2016.08.08 55
38 wp 워드프레스 플러그인 만들기 file 졸리운_곰 2016.08.08 1726
37 워드프레스 – 코드플로우(URL에서 페이지까지) 졸리운_곰 2016.07.21 156
36 워드프레스 데이터베이스 들여다보기. file 졸리운_곰 2016.07.21 72
35 워드프레스 웹페이지 구조와 구성요소인 템플릿 파일 이해하기. 졸리운_곰 2016.07.21 352
34 기본적으로 알아야할 워드프레스 파일 구조 및 디렉터리 구조 file 졸리운_곰 2016.07.21 218
33 워드프레스의 기본 구조에 대해 알아보자 file 졸리운_곰 2016.07.21 70
32 php에서 외부 명령어 실행하기 졸리운_곰 2016.05.10 144
31 php함수정리 졸리운_곰 2016.05.10 110
30 10분 안에 PHP 확장 모듈 만들기 file 졸리운_곰 2016.05.10 66
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED