메뉴 건너뛰기

프로그램언어

조회 수 241 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

php 언어로  간단하게 달력 만드는 소스 입니다.

 

 

 

<?php
//---- 오늘 날짜
$thisyear = date('Y'); // 4자리 연도
$thismonth = date('n'); // 0을 포함하지 않는 월
$today = date('j'); // 0을 포함하지 않는 일

//------ $year, $month 값이 없으면 현재 날짜
$year = isset($_GET['year']) ? $_GET['year'] : $thisyear;
$month = isset($_GET['month']) ? $_GET['month'] : $thismonth;
$day = isset($_GET['day']) ? $_GET['day'] : $today;

$prev_month = $month - 1;
$next_month = $month + 1;
$prev_year = $next_year = $year;
if ($month == 1) {
    $prev_month = 12;
    $prev_year = $year - 1;
} else if ($month == 12) {
    $next_month = 1;
    $next_year = $year + 1;
}
$preyear = $year - 1;
$nextyear = $year + 1;

$predate = date("Y-m-d", mktime(0, 0, 0, $month - 1, 1, $year));
$nextdate = date("Y-m-d", mktime(0, 0, 0, $month + 1, 1, $year));

// 1. 총일수 구하기
$max_day = date('t', mktime(0, 0, 0, $month, 1, $year)); // 해당월의 마지막 날짜
//echo '총요일수'.$max_day.'<br />';

// 2. 시작요일 구하기
$start_week = date("w", mktime(0, 0, 0, $month, 1, $year)); // 일요일 0, 토요일 6

// 3. 총 몇 주인지 구하기
$total_week = ceil(($max_day + $start_week) / 7);

// 4. 마지막 요일 구하기
$last_week = date('w', mktime(0, 0, 0, $month, $max_day, $year));
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <style>
    font.holy {font-family: tahoma;font-size: 20px;color: #FF6C21;}
    font.blue {font-family: tahoma;font-size: 20px;color: #0000FF;}
    font.black {font-family: tahoma;font-size: 20px;color: #000000;}
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table class="table table-bordered table-responsive">
  <tr align="center" >
    <td>
        <a href=<?php echo 'test2.html?year='.$preyear.'&month='.$month . '&day=1'; ?>>◀◀</a>
    </td>
    <td>
        <a href=<?php echo 'test2.html?year='.$prev_year.'&month='.$prev_month . '&day=1'; ?>>◀</a>
    </td>
    <td height="50" bgcolor="#FFFFFF" colspan="3">
        <a href=<?php echo 'test2.html?year=' . $thisyear . '&month=' . $thismonth . '&day=1'; ?>>
        <?php echo "  " . $year . '년 ' . $month . '월 ' . "  "; ?></a>
    </td>
    <td>
        <a href=<?php echo 'test2.html?year='.$next_year.'&month='.$next_month.'&day=1'; ?>>▶</a>
    </td>
    <td>
        <a href=<?php echo 'test2.html?year='.$nextyear.'&month='.$month.'&day=1'; ?>>▶▶</a>
    </td>
  </tr>
  <tr class="info">
    <th hight="30">일</td>
    <th>월</th>
    <th>화</th>
    <th>수</th>
    <th>목</th>
    <th>금</th>
    <th>토</th>
  </tr>

  <?php
    // 5. 화면에 표시할 화면의 초기값을 1로 설정
    $day=1;

    // 6. 총 주 수에 맞춰서 세로줄 만들기
    for($i=1; $i <= $total_week; $i++){?>
  <tr>
    <?php
    // 7. 총 가로칸 만들기
    for ($j = 0; $j < 7; $j++) {
        // 8. 첫번째 주이고 시작요일보다 $j가 작거나 마지막주이고 $j가 마지막 요일보다 크면 표시하지 않음
        echo '<td height="50" valign="top">';
        if (!(($i == 1 && $j < $start_week) || ($i == $total_week && $j > $last_week))) {

            if ($j == 0) {
                // 9. $j가 0이면 일요일이므로 빨간색
                $style = "holy";
            } else if ($j == 6) {
                // 10. $j가 0이면 토요일이므로 파란색
                $style = "blue";
            } else {
                // 11. 그외는 평일이므로 검정색
                $style = "black";
            }

            // 12. 오늘 날짜면 굵은 글씨
            if ($year == $thisyear && $month == $thismonth && $day == date("j")) {
                // 13. 날짜 출력
                echo '<font class='.$style.'>';
                echo $day;
                echo '</font>';
            } else {
                echo '<font class='.$style.'>';
                echo $day;
                echo '</font>';
            }
            // 14. 날짜 증가
            $day++;
        }
        echo '</td>';
    }
 ?>
  </tr>
  <?php } ?>
</table>
</div>

</body>
</html>

 


  1. PHP 네이버블로그 원격 글쓰기 API 소스

    Date2018.02.09 Views12465
    Read More
  2. php 내장함수

    Date2017.03.07 Views17004
    Read More
  3. PHP 날짜/시간 정리

    Date2017.03.07 Views18629
    Read More
  4. PHP 날짜, 시간 관련 함수. date(), mktime()

    Date2017.03.06 Views16707
    Read More
  5. PHP 날짜 함수

    Date2017.04.13 Views17673
    Read More
  6. php 간단 심플한 달력만들기

    Date2023.01.12 Views241
    Read More
  7. PHP 가변변수 $$

    Date2019.02.19 Views1449
    Read More
  8. PHP ZIP 압축파일 만들기

    Date2023.01.12 Views251
    Read More
  9. PHP XML 문서파싱 (SAX 방식 , DOM 방식)

    Date2018.10.27 Views3585
    Read More
  10. php www 붙이기

    Date2023.01.12 Views234
    Read More
  11. PHP switch 문

    Date2015.04.14 Views20993
    Read More
  12. PHP str_replace php 문자열치환

    Date2023.01.12 Views197
    Read More
  13. PHP split()와 explode()의 차이점

    Date2018.10.27 Views3536
    Read More
  14. PHP SimpleHtmlDom Parser로 HTML 파싱하기

    Date2023.01.12 Views220
    Read More
  15. PHP Notice: Use of undefined constant ... assumed ... 오류

    Date2021.03.26 Views308
    Read More
  16. PHP Mcrypt 라이브러리를 활용한 암호화 시스템

    Date2016.12.22 Views19972
    Read More
  17. PHP http 를 https 로 전환(redirect), http->https

    Date2019.02.19 Views2183
    Read More
  18. PHP http -> https 로 전환

    Date2023.01.12 Views236
    Read More
  19. PHP EXCEL export시 시트 이름 지정하여 여러 시트에 데이터 쓰기

    Date2017.03.06 Views18266
    Read More
  20. PHP error 메시지 출력

    Date2015.04.14 Views20924
    Read More
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved