一個(gè)PHP日歷程序
更新時(shí)間:2006年12月06日 00:00:00 作者:
<?php
//<-------處理通過GET方法提交的變量;開始-------->
if($HTTP_GET_VARS[year]=="")
{
$HTTP_GET_VARS[year]=date("Y");
}
if($HTTP_GET_VARS[month]=="")
{
$HTTP_GET_VARS[month]=date("n");
}
$month=$HTTP_GET_VARS[month];
$year=$HTTP_GET_VARS[year];
//<-------處理通過GET方法提交的變量;結(jié)束-------->
if($year<1971)
{
echo "出錯(cuò)!";
echo "<BR>";
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]>Back</a>";
exit();
}
?>
<table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#E7E7E7" style="font-size:12px;" align="center">
<tr align="center"><td colspan="2">
<?php
//<-------當(dāng)月份超出1至12時(shí)的處理;開始------->
if($month<1)
{
$month=12;
$year-=1;
}
if($month>12)
{
$month=1;
$year+=1;
}
//<-------當(dāng)月份超出1至12時(shí)的處理;結(jié)束------->
//***************************************
//<---------上一年,下一年,上月,下月的連接處理及輸出;開始--------->
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]?year=".($year-1)."&month=".$month."><<</a>年<a href=$HTTP_SERVER_VARS[PHP_SELF]?year=".($year+1)."&month=".$month.">>></a>";
?>
</td><td colspan="3"><?php echo $year."年".$month."月";?>
</td><td colspan="2">
<?php
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]?month=".($month-1)."&year=".$year."><<</a>月<a href=$HTTP_SERVER_VARS[PHP_SELF]?month=".($month+1)."&year=".$year.">>></a>";
//<--------上一年,下一年,上月,下月的連接處理及輸出;結(jié)束--------->
?></td></tr>
<tr align=center><td><font color="red">日</font></td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr><tr>
<?php
$d=date("d");
$FirstDay=date("w",mktime(0,0,0,$month,1,$year));//取得任何一個(gè)月的一號(hào)是星期幾,用于計(jì)算一號(hào)是由表格的第幾格開始
$bgtoday=date("d");
function font_color($month,$today,$year)//用于計(jì)算星期天的字體顏色
{
$sunday=date("w",mktime(0,0,0,$month,$today,$year));
if($sunday=="0")
{
$FontColor="red";
}
else
{
$FontColor="black";
}
return $FontColor;
}
function bgcolor($month,$bgtoday,$today_i,$year)//用于計(jì)算當(dāng)日的背景顏色
{
$show_today=date("d",mktime(0,0,0,$month,$today_i,$year));
$sys_today=date("d",mktime(0,0,0,$month,$bgtoday,$year));
if($show_today==$sys_today)
{
$bgcolor="bgcolor=#6699FF";
}
else
{
$bgcolor="";
}
return $bgcolor;
}
function font_style($month,$today,$year)//用于計(jì)算星期天的字體風(fēng)格
{
$sunday=date("w",mktime(0,0,0,$month,$today,$year));
if($sunday=="0")
{
$FontStyle="<strong>";
}
else
{
$FontStyle="";
}
return $FontStyle;
}
for($i=0;$i<=$FirstDay;$i++)//此for用于輸出某個(gè)月的一號(hào)位置
{
for($i;$i<$FirstDay;$i++)
{
echo "<td align=center> </td>\n";
}
if($i==$FirstDay)
{
echo "<td align=center ".bgcolor($month,$bgtoday,1,$year)."><font color=".font_color($month,1,$year).">".font_style($month,1,$year)."1</font></td>\n";
if($FirstDay==6)//判斷1號(hào)是否星期六
{
echo "</tr>";
}
}
}
$countMonth=date("t",mktime(0,0,0,$month,1,$year));//某月的總天數(shù)
for($i=2;$i<=$countMonth;$i++)//輸出由1號(hào)定位,隨后2號(hào)直至月尾的所有號(hào)數(shù)
{
echo "<td align=center ".bgcolor($month,$bgtoday,$i,$year)."><font color=".font_color($month,$i,$year).">".font_style($month,$i,$year)."$i</font></td>\n";
if(date("w",mktime(0,0,0,$month,$i,$year))==6)//判斷該日是否星期六
{
echo "</tr>\n";
}
}
?>
</table>
//<-------處理通過GET方法提交的變量;開始-------->
if($HTTP_GET_VARS[year]=="")
{
$HTTP_GET_VARS[year]=date("Y");
}
if($HTTP_GET_VARS[month]=="")
{
$HTTP_GET_VARS[month]=date("n");
}
$month=$HTTP_GET_VARS[month];
$year=$HTTP_GET_VARS[year];
//<-------處理通過GET方法提交的變量;結(jié)束-------->
if($year<1971)
{
echo "出錯(cuò)!";
echo "<BR>";
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]>Back</a>";
exit();
}
?>
<table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#E7E7E7" style="font-size:12px;" align="center">
<tr align="center"><td colspan="2">
<?php
//<-------當(dāng)月份超出1至12時(shí)的處理;開始------->
if($month<1)
{
$month=12;
$year-=1;
}
if($month>12)
{
$month=1;
$year+=1;
}
//<-------當(dāng)月份超出1至12時(shí)的處理;結(jié)束------->
//***************************************
//<---------上一年,下一年,上月,下月的連接處理及輸出;開始--------->
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]?year=".($year-1)."&month=".$month."><<</a>年<a href=$HTTP_SERVER_VARS[PHP_SELF]?year=".($year+1)."&month=".$month.">>></a>";
?>
</td><td colspan="3"><?php echo $year."年".$month."月";?>
</td><td colspan="2">
<?php
echo "<a href=$HTTP_SERVER_VARS[PHP_SELF]?month=".($month-1)."&year=".$year."><<</a>月<a href=$HTTP_SERVER_VARS[PHP_SELF]?month=".($month+1)."&year=".$year.">>></a>";
//<--------上一年,下一年,上月,下月的連接處理及輸出;結(jié)束--------->
?></td></tr>
<tr align=center><td><font color="red">日</font></td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr><tr>
<?php
$d=date("d");
$FirstDay=date("w",mktime(0,0,0,$month,1,$year));//取得任何一個(gè)月的一號(hào)是星期幾,用于計(jì)算一號(hào)是由表格的第幾格開始
$bgtoday=date("d");
function font_color($month,$today,$year)//用于計(jì)算星期天的字體顏色
{
$sunday=date("w",mktime(0,0,0,$month,$today,$year));
if($sunday=="0")
{
$FontColor="red";
}
else
{
$FontColor="black";
}
return $FontColor;
}
function bgcolor($month,$bgtoday,$today_i,$year)//用于計(jì)算當(dāng)日的背景顏色
{
$show_today=date("d",mktime(0,0,0,$month,$today_i,$year));
$sys_today=date("d",mktime(0,0,0,$month,$bgtoday,$year));
if($show_today==$sys_today)
{
$bgcolor="bgcolor=#6699FF";
}
else
{
$bgcolor="";
}
return $bgcolor;
}
function font_style($month,$today,$year)//用于計(jì)算星期天的字體風(fēng)格
{
$sunday=date("w",mktime(0,0,0,$month,$today,$year));
if($sunday=="0")
{
$FontStyle="<strong>";
}
else
{
$FontStyle="";
}
return $FontStyle;
}
for($i=0;$i<=$FirstDay;$i++)//此for用于輸出某個(gè)月的一號(hào)位置
{
for($i;$i<$FirstDay;$i++)
{
echo "<td align=center> </td>\n";
}
if($i==$FirstDay)
{
echo "<td align=center ".bgcolor($month,$bgtoday,1,$year)."><font color=".font_color($month,1,$year).">".font_style($month,1,$year)."1</font></td>\n";
if($FirstDay==6)//判斷1號(hào)是否星期六
{
echo "</tr>";
}
}
}
$countMonth=date("t",mktime(0,0,0,$month,1,$year));//某月的總天數(shù)
for($i=2;$i<=$countMonth;$i++)//輸出由1號(hào)定位,隨后2號(hào)直至月尾的所有號(hào)數(shù)
{
echo "<td align=center ".bgcolor($month,$bgtoday,$i,$year)."><font color=".font_color($month,$i,$year).">".font_style($month,$i,$year)."$i</font></td>\n";
if(date("w",mktime(0,0,0,$month,$i,$year))==6)//判斷該日是否星期六
{
echo "</tr>\n";
}
}
?>
</table>
相關(guān)文章
詳解Laravel5.6 Passport實(shí)現(xiàn)Api接口認(rèn)證
這篇文章主要介紹了詳解Laravel5.6 Passport實(shí)現(xiàn)Api接口認(rèn)證,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
Yii 2.0自帶的驗(yàn)證碼使用經(jīng)驗(yàn)分享
這篇文章主要給大家介紹了關(guān)于使用Yii 2.0自帶驗(yàn)證碼的一些經(jīng)驗(yàn),方便新手們快速上手,對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-06-06
PHP實(shí)現(xiàn)支付寶即時(shí)到賬功能
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)支付寶即時(shí)到賬功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
php下載文件,添加響應(yīng)頭的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)硪黄猵hp下載文件,添加響應(yīng)頭的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09
利用Laravel生成Gravatar頭像地址的優(yōu)雅方法
Gravatar是一圖像跟隨著您到訪過的網(wǎng)站,當(dāng)您在博客中留言或發(fā)表文章,它將會(huì)出現(xiàn)在您的名稱旁。下面這篇文章主要給大家介紹了關(guān)于利用Laravel如何生成 Gravatar 頭像地址的優(yōu)雅方法,需要的朋友可以參考下。2017-12-12
Yii框架使用魔術(shù)方法實(shí)現(xiàn)跨文件調(diào)用功能示例
這篇文章主要介紹了Yii框架使用魔術(shù)方法實(shí)現(xiàn)跨文件調(diào)用功能,涉及Yii框架中php面向?qū)ο蟪绦蛟O(shè)計(jì)相關(guān)操作技巧,需要的朋友可以參考下2017-05-05
PHP中empty和isset對(duì)于參數(shù)結(jié)構(gòu)的判斷及empty()和isset()的區(qū)別
這篇文章主要介紹了PHP中empty和isset對(duì)于參數(shù)結(jié)構(gòu)的判斷及empty()和isset()的區(qū)別的相關(guān)資料,需要的朋友可以參考下2015-11-11

