
使用用php打印输出2022年12个月日历,如图所示。应该怎么写
<style>
div{ width:880px;display: flex;margin:0 auto;}
table{ width:210px; margin:5px;}
.selected{
color: red;
}
td{
border: 0px solid #ddd;
width: 30px;
text-align: center;
}
a{
color: blue;
}
</style>
<div>
<?php
/*
* php输出日期
*/
header('content-type:text/html;charset=utf-8');
$now_date = date('Y-m-d');
for($m=1;$m<=12;$m++){
$date['date']='2022-'.$m;
$date['date']= $date['date'] ? date('Y-m',strtotime($date['date'])) : date('Y-m');
$date['year'] = date('Y',strtotime($date['date']));
$date['month']= date('m',strtotime($date['date']));
$date['start_week'] = date('w', mktime(null,null,null,$date['month'],1,$date['year']));
$date['days']= date('t',strtotime($date['date']));
$date['week'] = array (
'星期日',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六'
);
?>
<table>
<tr>
<td colspan="7" style="background:#CCC"><?php echo $date['date']; ?></td>
</tr>
<tr>
<td>日</td>
<td>一</td>
<td>二</td>
<td>三</td>
<td>四</td>
<td>五</td>
<td>六</td>
</tr>
<?php
$start_week_html = '';
for($i=0;$i<$date['start_week'];$i++){
$start_week_html .= '<td></td>';
}
for ($d=1;$d<=$date['days'];$d++){
echo $i%7==0 ? '<tr>': '';
echo $d==1 ?$start_week_html :'';
?>
<td <?php echo $date['date'].'-'.$d == $now_date ? 'class="selected"' : '' ; ?>><?php echo $d;?></td>
<?php
echo $i%7==6 ? '</tr>' :'';
$i++;
}
?>
</table>
<?php
echo ($m %4===0 && $m<12) ? '</div><div>' :'';
}
?>
</div>
请看: https://so.csdn.net/so/search?spm=1001.2014.3001.4498&q=php%E6%89%93%E5%8D%B0%E8%BE%93%E5%87%BA%E6%97%A5%E5%8E%86&t=blog&u=