我想用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 ?>
扬帆大鱼
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"; }
- 2 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消