php日历表代码,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); //獲取下一個月的開始日期作為月歷輸出的截止時間
$thedate = getdate($startdate); //把日期轉化為字符串格式
$color = $backcolor[$mon]; //設置月歷的背景顏色
echo("
$ym = $year . "年". $month[$mon];
echo("
$ym
");echo("
");for ($i=0; $i<7; $i++) //輸出星期幾
{
echo("
");echo("
$week[$i]
");echo("
");}
echo("
");$theweek = $thedate[wday];//判斷當天是星期幾
for ($i=0; $i<6; $i++)
{
echo("
");for ($j=0; $j<7; $j++)
{
echo("
");if ($startdate < $enddate && $theweek == $j)//把日期輸出到對應的星期幾所在列,并注意不要超出本月日期
{
$theday = $thedate[mday];
echo("
$theday
");$startdate = strtotime("+1 day", $startdate); //日期前移1天
$thedate = getdate($startdate);//更新日期
$theweek = ($theweek + 1) % 7;//更新星期
}
echo("
");}
echo("
");if ($startdate == $enddate) //如果已經輸出全部日期,結束循環
{
$i = 6;
}
}
echo("
}
?>
請輸入要查看的年號和月份(查詢范圍為1970年1月1日至2038年)
年月
$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("月份不對" . "
");
}
}
else if($year != null)
{
echo("年份不對" . "
");
}
?>
總結
以上是生活随笔為你收集整理的php日历表代码,PHP输出日历表代码实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于matlab道路交通标志牌,基于MA
- 下一篇: LabVIEW Arduino ZigB