메뉴 건너뛰기

프로그램언어

조회 수 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 버전 숨기기 ( php version hide )

    Date2024.02.07 Views69
    Read More
  2. php 암호화 복호화 , 간단한 암호화

    Date2023.01.12 Views358
    Read More
  3. PHP 디렉토리안에 파일 리스트 가져오기

    Date2023.01.12 Views231
    Read More
  4. 그누보드 https 보안서버 연결시 오류

    Date2023.01.12 Views280
    Read More
  5. php 두날짜 사이의 모든날짜 배열 만들기

    Date2023.01.12 Views178
    Read More
  6. php 간단 심플한 달력만들기

    Date2023.01.12 Views241
    Read More
  7. 간단한 캡차파일 만들기 captcha

    Date2023.01.12 Views260
    Read More
  8. PHP str_replace php 문자열치환

    Date2023.01.12 Views197
    Read More
  9. curl을 이용하여 post, get 방식 으로 데이터 전송하기

    Date2023.01.12 Views328
    Read More
  10. php 이미지 리사이징 image resizing

    Date2023.01.12 Views258
    Read More
  11. PHP ZIP 압축파일 만들기

    Date2023.01.12 Views251
    Read More
  12. ereg(), eregi(), ereg_replace(), eregi_replace(), split() 대체

    Date2023.01.12 Views227
    Read More
  13. PHP 브라우저 알아내기

    Date2023.01.12 Views253
    Read More
  14. PHP SimpleHtmlDom Parser로 HTML 파싱하기

    Date2023.01.12 Views216
    Read More
  15. 웹페이지 파싱

    Date2023.01.12 Views225
    Read More
  16. 폴더 용량 체크

    Date2023.01.12 Views218
    Read More
  17. 코드 생성 하기

    Date2023.01.12 Views213
    Read More
  18. PHP웹 보안 취약점 TOP5(웹해킹)

    Date2023.01.12 Views292
    Read More
  19. PHP 하위 디렉토리 포함 디렉토리 리스트 출력

    Date2023.01.12 Views236
    Read More
  20. PHP 파일 업로드 FORM 처리

    Date2023.01.12 Views229
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved