亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問有沒有精簡一點的方法來生成我要的日歷呢,就像下面這種?

請問有沒有精簡一點的方法來生成我要的日歷呢,就像下面這種?

PHP
翻過高山走不出你 2023-04-14 14:10:25
我想用php生成一段日歷的html代碼,而且這個日歷是可以指定年份自動生成的,網上的代碼都過于臃腫,要不就是搞了一個Class來生成,要不就是有一些我不要的功能。
查看完整描述

2 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

<?php
  $year = '2013';  $months =  array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec' );  $days = array( 31, 
                 (strtotime("1 Mar ".$year) - strtotime("1 Feb ".$year)) / ( 24 * 60 * 60 ),                 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );  $wday = array( '', '', '', '', '', '', '' );  $cal = array();  foreach(range(0, 11) as $i) {    $firstday = getdate(strtotime('1 '.$months[$i].' '.$year));    $fromday = $firstday['wday'];    $leftday =  7 - ( $fromday + $days[$i] ) % 7;    $cal[] = array_merge( array_slice($wday, 0, $fromday),                          range(1, $days[$i]),                          array_slice($wday, 0, $leftday)
                        );
  }?><?php foreach(range(0, 11) as $i) : ?><table>
  <thead>
    <tr><th colspan="7"><?php echo $months[$i].' '.$year; ?></th></tr>
    <tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th>
  </thead>
  <tbody>
    <tr>
    <?php
    foreach($cal[$i] as $k => $v) {      if($k && !($k % 7)) echo "</tr><tr>";      echo "<td>{$v}</td>";
    }    ?>
    </tr>
  </tbody></table><?php endforeach ?>


查看完整回答
反對 回復 2023-04-17
?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

$begin = new DateTime( '2016-01-01' );    $end = (new DateTime( '2016-12-31' ))->modify( '+1 day' );    $interval = new DateInterval('P1D');    $daterange = new DatePeriod($begin, $interval ,$end);    foreach($daterange as $date){        echo $date->format("Y-m-d"). "\n";
    }


查看完整回答
反對 回復 2023-04-17
  • 2 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號