php 간단한 달력

php 간단한 달력

QA

php 간단한 달력

본문

$start_youil 의 출력  4를 이용하여 

목요일부터 1이 시작되고 싶은데, 

공간을 남겨두고 밀어서 시작하기 어렵습니다.


$year = date('Y');
$month = date('n');
list($last_day, $start_youil) = preg_split('[ ]',date('t w',mktime(0,0,1,$month,1,$year)));
echo "<table border=1>";
echo "<tr align=center><td colspan=7>{$month} 월</td></tr>";
echo "<tr align=center><th>일</th><th>월</th><th>화</th><th>수</th><th>목</th><th>금</th><th>토</th></tr>";
echo "<tr align=center>";
for($i=1; $i<=$last_day; $i++) {
    echo "<td> {$i} </td>";
    if($i%7==0) {
        echo "</tr><tr>";
    }
}
echo "</table>";

[ 현 코드 출력 결과 ]

7 월

일월화수목금토

1234567

891011121314

15161718192021

22232425262728

293031

[ 원하는 결과 ]

일월화수목금토

            123

45678910

11121314151617

18192021222324

25262728293031

입니다. 

 

이 질문에 댓글 쓰기 :

답변 3


echo "<tr align=center>";
for($i=0; $i<date('w',mktime(0,0,0,$month,1,$year)); $i++) {
   echo "<td></td>";
}
for($i=1; $i<=$last_day; $i++) {
    echo "<td> {$i} </td>";
    if($i%7==0) {
        echo "</tr><tr>";
    }
}

감사합니다. 아래 결과처럼 밀려만 갑니다.
일 월 화 수 목 금 토
                1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
4부터 내려가서 자리를 잡을 수 있는 방법.......

https://www.php.net/manual/en/datetime.format.php

l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday
N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)

 

오늘이 무슨 요일이냐에 따라서

처음 빈 칸을 만들어 주면 됩니다.


$j = 1;
for($i = (1 - $start_youil); $i <= $last_day; $i++) {
    echo $i > 0 ? "<td>".$i."</td>" : "<td></td>";
    if($j % 7 == 0) echo "</tr><tr>";
    $j++;
}

이렇게 해 보셔도 될 것 같습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 123,529 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT