A simple calendar implementation. I don’t know if there is any problem with the implementation method of this code. I didn’t refer to my predecessors. After you understand my bad code, it will be more helpful to appreciate other people’s excellent code.
- #calendardiv,# calendar{width:252px;}
- #cal_title{height:33px;line-height:33px;text-align:center;overflow:hidden;}
- #cal_title strong{font-weight:bold;font-size:14px; }
- #cal_title a{font-weight:bold;font-size:14px;text-decoration:none;}
- #calendar{border-collapse:collapse;}
- #calendar td{
- text-align:center;
- width: 35px;
- height:20px;
- line-height:20px;
- background-color:#efefef;
- border-bottom:1px solid #fff;
- border-right:1px solid #fff;
- }
- #calendar .even td {background-color:#e6e6e6;}
- #calendar td .current{display:block;background-color:#f60;color:#fff;}
- #calendar .current{background-color:#f60!important;color: #fff;}
- #week td{color:#fff;background-color:#373737;}
- $date = isset( $_GET['d']) ? intval($_GET['d']) : '';
- if($date)
- {
- $y = substr($date,0,4);
- $m = substr ($date,4,2);
- $cur = mktime(0,0,0,$m,1,$y);
- }
- else
- {
- $cur = mktime();
- }
- list( $year,$month,$day) = explode('-',date('Y-m-d',$cur));//Year, month and day
- $p = date('Ym',strtotime('last months' ,$cur));//The previous month
- $n = date('Ym',strtotime('next months',$cur));//The next month
- $t = date('t',$cur ); //How many days in the month
- $s = date('w',mktime(0,0,0,$month,1,$year)); //Padding blanks
- $e = 6-(date(' w',mktime(0,0,0,$month,$t,$year)));//Fill in the blanks
- ?>
« =$year?>year=$month?>month »
day | < td>OneTwo | Three | Four | Five | < td>六
- echo '
';
- for($i=0;$i<$s;$i++)
- {
- echo '
| ';
- }
- for($d=1;$d<=$t;$d++)
- {
- $current=$d==$day ?'class="current"':'';//Current style
- $r = ($d+$s)%7;//Line break
- echo "
$d | " ;
- if($r==0)
- {
- echo '
';
- echo '
';
- }
- }
- for($i=0;$ i<$e;$i++)
- {
- echo '
| ';
- }
- ?>
Copy code
|