一個(gè)PHP日歷程序
更新時(shí)間:2006年12月06日 00:00:00 作者:
<?php
//<-------處理通過(guò)GET方法提交的變量;開(kāi)始-------->
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];
//<-------處理通過(guò)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í)的處理;開(kāi)始------->
if($month<1)
{
$month=12;
$year-=1;
}
if($month>12)
{
$month=1;
$year+=1;
}
//<-------當(dāng)月份超出1至12時(shí)的處理;結(jié)束------->
//***************************************
//<---------上一年,下一年,上月,下月的連接處理及輸出;開(kāi)始--------->
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)是由表格的第幾格開(kāi)始
$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ò)GET方法提交的變量;開(kāi)始-------->
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];
//<-------處理通過(guò)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í)的處理;開(kāi)始------->
if($month<1)
{
$month=12;
$year-=1;
}
if($month>12)
{
$month=1;
$year+=1;
}
//<-------當(dāng)月份超出1至12時(shí)的處理;結(jié)束------->
//***************************************
//<---------上一年,下一年,上月,下月的連接處理及輸出;開(kāi)始--------->
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)是由表格的第幾格開(kāi)始
$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)文章
php微信公眾號(hào)開(kāi)發(fā)之校園圖書(shū)館
這篇文章主要為大家詳細(xì)介紹了php微信公眾號(hào)開(kāi)發(fā)之校園圖書(shū)館,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10Thinkphp5.0 框架視圖view的比較標(biāo)簽用法分析
這篇文章主要介紹了Thinkphp5.0 框架視圖view的比較標(biāo)簽用法,結(jié)合實(shí)例形式分析了thinkPHP5框架eq、equal、neq、notequal、egt及switch、range、between等標(biāo)簽相關(guān)用法,需要的朋友可以參考下2019-10-10將PHP程序中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法
這篇文章主要介紹了將PHP中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法,文中示例環(huán)境為L(zhǎng)inux系統(tǒng)與Apache服務(wù)器,需要的朋友可以參考下2016-03-03typecho插件編寫(xiě)教程(一):Hello World
這篇文章主要介紹了typecho插件編寫(xiě)教程(一):Hello World,本文講解了插件的文件結(jié)構(gòu)、插件信息、插件結(jié)構(gòu)、插件流程等內(nèi)容,需要的朋友可以參考下2015-05-05PHP 中TP5 Request 請(qǐng)求對(duì)象的實(shí)例詳解
這篇文章主要介紹了PHP 中TP5 Request 請(qǐng)求對(duì)象的實(shí)例詳解的相關(guān)資料,這里提供實(shí)現(xiàn)代碼幫助大家理解這部分內(nèi)容,需要的朋友可以參考下2017-07-07CI框架實(shí)現(xiàn)遞歸生成文件路徑并重新生成圖片功能
這篇文章主要介紹了CI框架實(shí)現(xiàn)遞歸生成文件路徑并重新生成圖片功能,涉及CodeIgniter框架自定義圖片控制器類實(shí)現(xiàn)文件目錄遞歸以及調(diào)用圖片處理擴(kuò)展類進(jìn)行圖片生成相關(guān)操作技巧,需要的朋友可以參考下2018-06-06ThinkPhP+Apache+PHPstorm整合框架流程圖解
這篇文章主要介紹了ThinkPhP+Apache+PHPstorm整合框架流程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11PHP實(shí)現(xiàn)Javascript中的escape及unescape函數(shù)代碼分享
這篇文章主要介紹了PHP實(shí)現(xiàn)Javascript中的escape及unescape函數(shù)代碼分享,本文給出兩個(gè)實(shí)現(xiàn)版本,需要的朋友可以參考下2015-02-02