php代码编写一个日历功能的网页!代码实现
代码实现:
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php header("Content-Type:text/html;charset=utf-8"); echo "<style>table{margin:0 auto;background-color:yellow;}td{border:1px solid darkgray}</style>"; date_default_timezone_set("PRC"); $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?$month=1:$month-1; $m_lnk2=$month>=12?$month=12:$month+1; echo "<table><tr>"; echo "<td colspan=4><a href='优化日历.php?year=$y_lnk1&month=$month'> <</a>".$year."年<a href='优化日历.php?year=$y_lnk2&month=$month'>></a></td>"; echo "<td colspan=3><a href='优化日历.php?year=$year&month=$m_lnk1'> <</a>".$month."月<a href='优化日历.php?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 style='background-color:hotpink'>"; if($i>=$wd){ if($date==$day&&$month==date("n")&&$year==date("Y")) echo"<b><font color=red style='background-color:lavender'>".$day."</font></b>"; else echo $date; } echo"</td>"; if($i%7==6) echo "</tr>"; } echo "</table>"; ?> </body> </html>
php代码编写一个日历功能的网页!本代码主要使用到了函数库,还有如何获取日历的参数!
p105