PHP 간단 한 달력 구현 방법

2027 단어 PHP일력
이 글 은 PHP 의 간단 한 달력 실현 방법 을 실례 로 서술 하 였 다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.
실행 효과 캡 처 는 다음 과 같 습 니 다:

구체 적 인 코드 는 다음 과 같다.

<?php
/*
 * Created on 2016-7-20
 */
SimCalendar('2016-08');//  8    
function SimCalendar($date)
{
  /**
   *       ,     cal_days_in_month   
   * @param $date Y-m       
   */
  echo '<table border="1">
  <thead>
    <tr>
      <th> </th>
      <th> </th>
      <th> </th>
      <th> </th>
      <th> </th>
      <th> </th>
      <th> </th>
    </tr>
  </thead>
  <tbody>';
    $date_array = explode('-', $date);
    $start_week = 0;//       0
    $month = cal_days_in_month(CAL_GREGORIAN, $date_array[1], $date_array[0]);//     
    $wstar = date('w', strtotime($date . '-01'));//        
    $rows = ceil(($wstar + $month) / 7);//   
    $mday = 1;//   
    for ($i = 0; $i < $rows; $i++) {
      echo '<tr>';
      for ($d = 0; $d < 7; $d++) {
        $nowday = 7 * $i + $d + $start_week;
        if ($nowday >= $wstar && $mday <= $month) {
          $temp = date('d', strtotime($date . '-' . $mday));
          echo '<td>'.$temp . '</td>';
          $mday++;
        } else {
          echo '<td>&nbsp;</td>';
        }
      }
      echo '</tr>';
    }
  echo '</tbody>
</table>';
}
?>

더 많은 PHP 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 논문 에서 말 한 것 이 여러분 의 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기