這篇文章給大家介紹使用php怎么編寫一個(gè)日歷小程序,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)專注于建鄴企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),商城網(wǎng)站開發(fā)。建鄴網(wǎng)站建設(shè)公司,為建鄴等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)具體如下:
<?php ////判斷$Year和$Month是否為空,如果為空就獲取系統(tǒng)當(dāng)前日期,否則用$_GET獲取 $Year = empty($_GET['Year']) ? date("Y"): $_GET["Year"]; $Month = empty($_GET['Month']) ? date("m"): $_GET["Month"]; ////獲取當(dāng)前日期//// $Today = date("Ymj"); ////初始化日期數(shù)組//// $Maxday = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20", "21","22","23","24","25","26","27","28","29","30","31"); $Maxday_count = count($Maxday); ////初始化星期數(shù)組//// $Weekday = array("<font color='red'>Sun</font>","Mon","Tue","Wed","Thu","Fri","<font color='red'>Sat</font>"); $Weekday_count = count($Weekday); $daynum = 0; $space = "<td> </td>"; $col = 0; ////打印表格頭部//// ?> <form action="calendar.php" method="post" name="linked"> <table><tr><td colspan=3 align=center><a href="?Year=<?php if($Year-1 > 1900)echo $Year-1;else echo $Year;?>&Month=<?php echo $Month?>" onClick="javascript:document.linked.submit();" name="Year"><<</a> <?php echo $Year?> <a href="?Year=<?php if($Year+1 <2999) echo $Year+1;else echo $Year;?>&Month=<?php echo $Month?>" onClick="javascript:document.linked.submit();" name="Year">>></a></td> <td> </td><td colspan=3 align=center><a href="?Year=<?php echo $Year?>&Month=<?php if($Month-1 >0) if($Month-1 < 10)echo "0".($Month-1); else echo $Month-1; else echo $Month;?>" onClick="javascript:document.linked.submit();" name="Month"><<</a> <?php echo $Month;?> <a href="?Year=<?php echo $Year?>&Month=<?php if($Month+1 <13) if($Month+1 <10) echo "0".($Month+1);else echo ($Month+1); else echo $Month;?>" onClick="javascript:document.linked.submit();" name="Month">>></a></td></tr><tr><td colspan="8"></td></tr><tr> <?php ////打印星期列表//// while(list(,$Weekvalue) = each($Weekday)) echo "<td align=center> ".$Weekvalue." </td>"; echo "</tr>"; ////打印日期列表//// //當(dāng)月份為4,6,9,11的時(shí)候,從數(shù)組末尾刪除一個(gè)值,也就是刪除31這個(gè)值. if($Month == 4 or $Month == 6 or $Month == 9 or $Month == 11) { array_pop($Maxday); $Maxday_count--; } //先判斷月份是否為2月,如果是的話再判斷年份是否為閏年,如果是的話就從數(shù)組尾部移除2個(gè)值,否則就移除3個(gè)值. if($Month == 2) { if($Year % 4 == 0) { array_pop($Maxday); array_pop($Maxday); $Maxday_count-=2; } else { array_pop($Maxday); array_pop($Maxday); array_pop($Maxday); $Maxday_count-=3; } } ////打印日期//// while($daynum < $Maxday_count) { echo "<tr>"; while(list($colnum,$Dayvalue) = each($Maxday)) { //判斷當(dāng)前日期為一星期中的哪一天 $DayWeek = date("w",strtotime($Year."-".$Month."-".$Dayvalue)); //當(dāng)當(dāng)前日期處于第1個(gè),也就是每個(gè)月的第1天的時(shí)候,在它前面補(bǔ)上相應(yīng)的空格子 if($Dayvalue == 1) for($i=0;$i<$DayWeek;$i++) echo $space;//打印每個(gè)月空出的幾個(gè)格子 $daynum++; //當(dāng)打印日期的時(shí)候與當(dāng)前日期字符串進(jìn)行比較,如果相等就將字體標(biāo)為紅色. if($Year.$Month.$Dayvalue == $Today) { $u1 = "<b><u>"; $u2 = "</b></u>"; } else { $u1 = ""; $u2 = ""; } if($DayWeek == 0 or $DayWeek == 6) $color = "red"; else $color = "black"; echo "<td align=center><font color=".$color."> ".$u1.$Dayvalue.$u2." </font></td>"; //用本周第幾天這個(gè)值加1,如果是7的倍數(shù)就換行退出此輪循環(huán)(換行打印) if(($DayWeek+1) % 7 == 0) { $col++; break; } } echo "</tr>"; } ?>
運(yùn)行效果如下:
關(guān)于使用php怎么編寫一個(gè)日歷小程序就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
文章名稱:使用php怎么編寫一個(gè)日歷小程序-創(chuàng)新互聯(lián)
本文鏈接:http://jinyejixie.com/article2/jejic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、服務(wù)器托管、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站策劃、網(wǎng)站制作、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)