PHP简单日历实例

<?php
/*
 * PHP简单日历实例
 * 作者: 多菜鸟
 * 邮箱: kingerq AT msn DOT com
 * 来源: http://blog.youkuaiyun.com/kingerq/
 * 创建时间: 2008-01-03
**/

$date = preg_match("//d{4}/-/d{2}/-/d{2}/", $_GET["YMD"]) ? $_GET["YMD"] : date( "Y-m-d" );
$thisYear = date( "Y", strtotime( $date) );
$thisMonth = date( "m", strtotime( $date) );
$firstDay = date( "w", strtotime( $thisYear."-".$thisMonth."-01" ) );
$monthNum = date( "t", strtotime( $date) );
?>
<html>
<head>
<title>Calendar</title>
<style type="text/css">
.datehead td{
  background-color: #669966;
  border: 1px solid #4F774F;
  color:#FFFFFF;
  height:30px;
  font-size:18px;
  font-weight:bold;
  text-align:center;
  font-family: Geneva, Arial, Helvetica, sans-serif;
}
.daynormalbg td{
 background-color:#EEEEEE;
 border:solid #dddddd 1px;
 height:100px;
 vertical-align: top;
 width:14%;
}
.daynormalfont div{
 color:#000000;
 font-weight:bold;
 font-size:18px;
 font-family: Geneva, Arial, Helvetica, sans-serif;
}
.sunday{color:#CC0000 !important; }
.saturday{color: #006600 !important;}
.todaybg{
 background-color:#0099FF !important;
 text-decoration: underline;
}
a {font-family:Geneva, Arial, Helvetica, sans-serif; color:#333333; font-size:12px}
a:hover{text-decoration:none;}
</style>
</head>

<body>
<table border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td>     
 <p><a href="?YMD=<?=date( "Y-m", strtotime( $date." -1 year") )."-01"?>">&lt;&lt;Last Year</a>
        <a href="?YMD=<?=date( "Y-m", strtotime( $date." -1 month") )."-01"?>">&lt;Last Month</a>
        <span class="sunday">
        <?=$date?>
        </span>
        <a href="?YMD=<?=date( "Y-m", strtotime( $date." +1 month") )."-01"?>">Next Month&gt;</a>
        <a href="?YMD=<?=date( "Y-m", strtotime( $date." +1 year") )."-01"?>">Next Year&gt;&gt;</a>
        <a href="?">Today</a> </p></td></tr>
</table>
<table width="95%" border="0" align="center" cellpadding="2" cellspacing="2" class="daynormalfont">
  <tr class="datehead">
    <td><div align="center" class="sunday">SUN</div></td>
    <td>MON</td>
    <td>TUE</td>
    <td>WED</td>
    <td>THU</td>
    <td>FRI</td>
    <td><div align="center" class="saturday">SAT</div></td>
  </tr>
<?php
$i = 1;
$num = 0;
while( 1 ) {//row
?>
  <tr class="daynormalbg">
<?php
  while( $i <= $monthNum ) {//list day
    while( $firstDay ) {//empty in front
?>
    <td>&nbsp;</td>
 <?php
   $firstDay--;
   $num++;
 }
 $daykey = str_pad($i, 2, 0, STR_PAD_LEFT);
 $thisDay = date("Y-m-d", strtotime($thisYear."-".$thisMonth."-".$daykey) );
 $week = date("w", strtotime($thisDay));
 $className = ( $week%7 == 0 ? " class='sunday'" : ( $week%7 == 6 ? " class='saturday'" : ""));
 ?>
    <td<?=($thisDay == date("Y-m-d") ? ' class="todaybg"' : "" ) ?>><div<?=$className?>><?=$i ?></div>   </td>
<?php
    $i++;
 $num++;
 if( $num % 7 == 0 ) break;
  }
  while( $num % 7 != 0 ) {//list empty cell
 ?>
    <td>&nbsp;</td>
<?php
    $num++;
  }
?>
  </tr>
<?php
  if( $i >= $monthNum ) break;
}
?>
  <tr class="datehead">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html> 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值