|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
《PHP+MYSQL WEB开发(第三版)》号称圣经级,(也许是个不错的选择(声明:作者没给我啥好处费,我也不是书托,隔着大老远,我连他老兄的面都没见过的说-_-)日历 <?php
class Calendar{
/*
* 日历
*
* @作者:sports98
* Email:flyruns@hotmail.com
* @版本:V1.0
*/
var $YEAR,$MONTH,$DAY;
var $WEEK=array("日曜日","礼拜一","礼拜二","礼拜三","木曜日","礼拜五","礼拜六");
var $_MONTH=array(
"01"=>"一月",
"02"=>"二月",
"03"=>"三月",
"04"=>"四月",
"05"=>"蒲月",
"06"=>"六月",
"07"=>"七月",
"08"=>"八月",
"09"=>"九月",
"10"=>"十月",
"11"=>"十一月",
"12"=>"十二月"
);
//设置年份
function setYear($year){
$this->YEAR=$year;
}
//取得年份
function getYear(){
return $this->YEAR;
}
//设置月份
function setMonth($month){
$this->MONTH=$month;
}
//取得月份
function getMonth(){
return $this->MONTH;
}
//设置日期
function setDay($day){
$this->DAY=$day;
}
//取得日期
function getDay(){
return $this->DAY;
}
//打印日历
function OUT(){
$this->_env();
$week=$this->getWeek($this->YEAR,$this->MONTH,$this->DAY);//取得日期为礼拜几 (例现在天为2003-07-18,礼拜五)
$fweek=$this->getWeek($this->YEAR,$this->MONTH,1);//取得此月第一天为礼拜几
echo "<div style=\"margin:0;border:1 solid black;width:300;font:9pt\">
<form action=$_SERVER[PHP_SELF] method=\"post\" style=\"margin:0\">
<select name=\"month\" onchange=\"this.form.submit();\">";
for($ttmpa=1;$ttmpa<13;$ttmpa++){//打印12个月
$ttmpb=sprintf("%02d",$ttmpa);
if(strcmp($ttmpb,$this->MONTH)==0){
$select="selected style=\"background-color:#c0c0c0\"";
}else{
$select="";
}
echo "<option value=\"$ttmpb\" $select>".$this->_MONTH[$ttmpb]."</option>\r\n";
}
echo " </select> <select name=\"year\" onchange=\"this.form.submit();\">";//打印年份,前后10年
for($ctmpa=$this->YEAR-10;$ctmpa<$this->YEAR+10;$ctmpa++){
if($ctmpa>2037){
break;
}
if($ctmpa<1970){
continue;
}
if(strcmp($ctmpa,$this->YEAR)==0){
$select="selected style=\"background-color:#c0c0c0\"";
}else{
$select="";
}
echo "<option value=\"$ctmpa\" $select>$ctmpa</option>\r\n";
}
echo "</select>
</form>
<table border=0 align=center>";
for($Tmpa=0;$Tmpa<count($this->WEEK);$Tmpa++){//打印礼拜标头
echo "<td>".$this->WEEK[$Tmpa];
}
for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++){//打印一切日期
if(strcmp($Tmpb,$this->DAY)==0){ //取得以后日期,做标志
$flag=" bgcolor='#ff0000'";
}else{
$flag=' bgcolor=#ffffff';
}
if($Tmpb==1){
echo "<tr>"; //增补打印
for($Tmpc=0;$Tmpc<$fweek;$Tmpc++){
echo "<td>";
}
}
if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0){
echo "<tr><td align=center $flag>$Tmpb";
}else{
echo "<td align=center $flag>$Tmpb";
}
}
echo "</table></div>";
}
//取得办法内指定的日期的礼拜数
function getWeek($year,$month,$day){
$week=date("w",mktime(0,0,0,$month,$day,$year));//取得礼拜
return $week;//取得礼拜
}
function _env(){
if(isset($_POST[month])){ //有指定月
$month=$_POST[month];
}else{
$month=date("m"); //默许为本月
}
if(isset($_POST[year])){ //有指年
$year=$_POST[year];
}else{
$year=date("Y"); //默许为今年
}
$this->setYear($year);
$this->setMonth($month);
$this->setDay(date("d"));
}
}
$D=new Calendar;
$D->OUT();
?> 在学习中,我也一直这样要求着自己。 |
|