php语言怎么编写日历功能?宗波尘客www.zbck123.com宗九尘博客

image.png

代码展示:

<?php
        header("Content-Type:text/html;charset=utf-8");
        date_default_timezone_set("PRC");
        echo "<style>table{margin:0 auto}td{border:1px solid #eee}</style>";
        $year=$_GET['year'];
        $month=$_GET['month'];
        if(empty($year))
            $year=date("Y");
        if(empty($month))
            $month=date("n");
        $day=date("j");
        $wd_ar=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
        $wd=date("w",mktime(0,0,0,$month,1,$year));
        $y_lnk1=$year<=1970 ? $year=1970:$year-1;
        $y_lnk2=$year>=2037 ? $year=2037:$year+1;
        $m_lnk1=$month<=1 ? $year=1:$year-1;
        $m_lnk2=$month>=12 ? $year=12:$year+1;
        echo "<table><tr>";
        echo "<td cospan=4><a href='calendar_ext.php?year=$y_lnk1&month=$month'><</a>".$year."年<a href='calendar_ext.php?year=$y_lnk2&month=$month'>></a></td>";
         echo "<td colspan=3><a href='calendar_ext.php?year=$year&month=$m_lnk1'><</a>".$month."月<a href='calendar_ext.php?year=$year=$year&month=$m_lnk2'>></a></td></tr>";
echo "<tr align=center>";
for($i=0;$i<7;$i++){
echo "<td>$wd_ar[$i]</td>";    
}
echo "</tr>";
$tnum = $wd + date("t",mktime(0,0,0,$month,1,$year));
for($i=0;$i<$tnum;$i++){
$date=$i + 1 - $wd;
if($i%7==0)
    echo "<tr align=center>";
echo "<td>";
if($i>$wd){
if($date==$day&&$month==date("n")&&$year==date("Y"))
echo "<b><font color=red>".$day."</font></b>";
else
echo $date;
}
echo "</td>";
    if($i%7==6)
        echo "</tr>";
}
echo "</table>";
?>

php语言怎么编写日历功能?宗波尘客www.zbck123.com宗九尘博客

php语言怎么编写日历功能?宗波尘客www.zbck123.com宗九尘博客

105页