PHP輸出日歷表代碼實(shí)例
來(lái)源:易賢網(wǎng) 閱讀:2088 次 日期:2015-03-30 11:29:44
溫馨提示:易賢網(wǎng)小編為您整理了“PHP輸出日歷表代碼實(shí)例”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了PHP輸出日歷表代碼實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>月歷表</title>

<?php

$MONTH = array("元月","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");

$enMONTH = array("元月","January" ,"February" ,"Marcy" ,"April" ,"May" ,"June" ,"July" ,"August" ,"September" ,"October" ,"November" ,"December");

$WEEK = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

$BACKCOLOR = array("#FFC" , "#FFF" , "#9F6" , "#FFC" , "#6F0" , "#6F6" , "#F90" , "#F06" , "#F00" , "#FC3" , "#FF6" , "#F99");

function PrintMon($year, $mon)

{

date_default_timezone_set("Asia/Shanghai");

global $MONTH;

global $enMONTH;

global $WEEK;

global $BACKCOLOR;

$startdate =strtotime("1 $enMONTH[$mon] $year"); //獲取查詢的年月

$enddate = strtotime("+1 month",$startdate); //獲取下一個(gè)月的開(kāi)始日期作為月歷輸出的截止時(shí)間

$theDate = getdate($startdate); //把日期轉(zhuǎn)化為字符串格式

$color = $BACKCOLOR[$mon]; //設(shè)置月歷的背景顏色

echo("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"$color\">");

$ym = $year . "年". $MONTH[$mon];

echo("<caption><h1>$ym</h1></caption>");

echo("<tr>");

for ($i=0; $i<7; $i++) //輸出星期幾

{

echo("<td width=\"90\", height=\"40\" align=\"center\" >");

echo("<h2>$WEEK[$i]</h2>");

echo("</td>");

}

echo("</tr>");

$theWeek = $theDate[wday];//判斷當(dāng)天是星期幾

for ($i=0; $i<6; $i++)

{

echo("<tr>");

for ($j=0; $j<7; $j++)

{

echo("<td width=\"90\", height=\"40\" align=\"center\" >");

if ($startdate < $enddate && $theWeek == $j)//把日期輸出到對(duì)應(yīng)的星期幾所在列,并注意不要超出本月日期

{

$theDay = $theDate[mday];

echo("<h2>$theDay</h2>");

$startdate = strtotime("+1 day", $startdate); //日期前移1天

$theDate = getdate($startdate);//更新日期

$theWeek = ($theWeek + 1) % 7;//更新星期

}

echo("</td>");

}

echo("</tr>");

if ($startdate == $enddate) //如果已經(jīng)輸出全部日期,結(jié)束循環(huán)

{

$i = 6;

}

}

echo("</table");

}

?>

</head>

<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

<h1>請(qǐng)輸入要查看的年號(hào)和月份(查詢范圍為1970年1月1日至2038年)</h1>

<input type="text" name="myYear">年<input type="text" name="myMonth">月

<input type="submit">

</form>

<?php

$year = $_POST['myYear'];

$month = $_POST['myMonth'];

if (is_numeric($year) && $year >= 1970 && $year <2038)

{

if (is_numeric($month) && $month >= 1 && $month <=12)

{

PrintMon($year, $month);

}

else if($month != NULL)

{

echo("月份不對(duì)" . "<br />");

}

}

else if($year != NULL)

{

echo("年份不對(duì)" . "<br />");

}

?>

</body>

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:PHP輸出日歷表代碼實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)