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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <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è)月的開始日期作為月歷輸出的截止時(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> </html> |
PHP輸出日歷表代碼實(shí)例
2020-09-15 15:50PHP之家 PHP教程
這篇文章主要介紹了PHP輸出日歷表代碼實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下
延伸 · 閱讀
- 2022-03-10簡(jiǎn)單談?wù)刢entos7中配置php
- 2022-03-06Ubuntu14.04服務(wù)器環(huán)境下配置PHP7.0+Apache2+Mysql5.7的方
- 2022-03-05centos yum php 7.x 無需刪除升級(jí)的方法
- 2022-03-05Centos7下PHP安裝gd庫(kù)的實(shí)例講解
- 2022-03-03linux環(huán)境下安裝PHP的OpenSSL擴(kuò)展的方法講解
- 2022-02-27CentOS 7.x編譯安裝Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4
- PHP教程
PHP基于php_imagick_st-Q8.dll實(shí)現(xiàn)JPG合成GIF圖片的方法
這篇文章主要介紹了PHP基于php_imagick_st-Q8.dll實(shí)現(xiàn)JPG合成GIF圖片的方法,需要的朋友可以參考下 ...
- PHP教程
Laravel框架使用Redis的方法詳解
這篇文章主要介紹了Laravel框架使用Redis的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Laravel框架中Redis數(shù)據(jù)庫(kù)配置、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以...
- PHP教程
PHP中使用匿名函數(shù)操作數(shù)據(jù)庫(kù)的例子
這篇文章主要介紹了PHP中使用匿名函數(shù)操作數(shù)據(jù)庫(kù)的例子,本文直接給出類的代碼、使用例子、繼承例子,需要的朋友可以參考下...
- PHP教程
eclipse php wamp配置教程
這篇文章主要為大家詳細(xì)介紹了eclipse php wamp配置教程,極其簡(jiǎn)單的php入門教程,感興趣的小伙伴們可以參考一下...
- PHP教程
PHP設(shè)計(jì)模式之迭代器模式Iterator實(shí)例分析【對(duì)象行為型】
這篇文章主要介紹了PHP設(shè)計(jì)模式之迭代器模式Iterator,結(jié)合實(shí)例形式分析了PHP迭代器模式Iterator相關(guān)概念、原理、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參...
- PHP教程
php 數(shù)組元素快速去重
本篇文章主要介紹了php數(shù)組元素快速去重的方法,具有很好的參考價(jià)值。下面跟著小編一起來看下吧...
- PHP教程
PHP之使用swoole統(tǒng)計(jì)在線人數(shù)和ID案例講解
這篇文章主要介紹了PHP之使用swoole統(tǒng)計(jì)在線人數(shù)和ID案例講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參...
- PHP教程
PHP里8個(gè)鮮為人知的安全函數(shù)分析
這篇文章主要介紹了PHP里8個(gè)鮮為人知的安全函數(shù),較為詳細(xì)的分析了addslashes、htmlentities、htmlspecialchars及md5等函數(shù)在PHP程序設(shè)計(jì)安全中所起到重要作用,非常...