![php簡單的日歷程序代碼_第1頁](http://file4.renrendoc.com/view/8cc3a7d039778f73c650bb2c4f610ffc/8cc3a7d039778f73c650bb2c4f610ffc1.gif)
![php簡單的日歷程序代碼_第2頁](http://file4.renrendoc.com/view/8cc3a7d039778f73c650bb2c4f610ffc/8cc3a7d039778f73c650bb2c4f610ffc2.gif)
![php簡單的日歷程序代碼_第3頁](http://file4.renrendoc.com/view/8cc3a7d039778f73c650bb2c4f610ffc/8cc3a7d039778f73c650bb2c4f610ffc3.gif)
![php簡單的日歷程序代碼_第4頁](http://file4.renrendoc.com/view/8cc3a7d039778f73c650bb2c4f610ffc/8cc3a7d039778f73c650bb2c4f610ffc4.gif)
![php簡單的日歷程序代碼_第5頁](http://file4.renrendoc.com/view/8cc3a7d039778f73c650bb2c4f610ffc/8cc3a7d039778f73c650bb2c4f610ffc5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
php簡單的日歷程序代碼PHP提供了date()函數(shù),該函數(shù)提供了豐富的日期處理功能。現(xiàn)在需要獲得的數(shù)據(jù)有兩個(gè),第一個(gè)是當(dāng)月的總天數(shù);第二個(gè)是該月的第一天所在星期中的第幾天,數(shù)字表示0(表示星期天)到6(表示星期六)。通過date()函數(shù)可以很容易獲得上面的數(shù)據(jù)
代碼如下復(fù)制代碼<?php$month=$_GET['m']?$_GET['m']:date(‘n’);
$year=$_GET['y']?$_GET['y']:date(‘Y’);$start_week=date(‘w’,mktime(0,0,0,$month,1,$year));
$day_num=date(‘t’,mktime(0,0,0,$month,1,$year));
$end=false;
?>
<table>
<tr>
<td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td>
</tr>
<tr>
<?php
for($i=0;$i<$start_week;$i++)
{
echo“<td></td>”;
}$j=1;while($j<=$day_num)
{
echo“<td>$j</td>”;
$week=($start_week+$j-1)%7;if($week==6){
echo“nt</tr>n”;
if($j!=$day_num)
echo“t<tr>ntt”;
else$end=true;
}
$j++;
}
while($week%7!=6)
{
echo“<td></td>”;
$week++;
}
if(!$end)
echo“n</tr>”;
?></table>高級一點(diǎn)類
代碼如下復(fù)制代碼<?php
classCalendar
{
private$year;
private$month;
private$weeks
=array('日','一','二','三','四','五','六');
function__construct($options=array()){
$this->year=date('Y');
$this->month=date('m');
$vars=get_class_vars(get_class($this));
foreach($optionsas$key=>$value){
if(array_key_exists($key,$vars)){
$this->$key=$value;
}
}
}
functiondisplay()
{
echo'<tableclass="calendar">';
$this->showChangeDate();
$this->showWeeks();
$this->showDays($this->year,$this->month);
echo'</table>';
}
privatefunctionshowWeeks()
{
echo'<tr>';
foreach($this->weeksas$title)
{
echo'<th>'.$title.'</th>';
}
echo'</tr>';
}
privatefunctionshowDays($year,$month)
{
$firstDay=mktime(0,0,0,$month,1,$year);
$starDay=date('w',$firstDay);
$days=date('t',$firstDay);
echo'<tr>';
for($i=0;$i<$starDay;$i++){
echo'<td> </td>';
}
for($j=1;$j<=$days;$j++){
$i++;
if($j==date('d')){
echo'<tdclass="today">'.$j.'</td>';
}else{
echo'<td>'.$j.'</td>';
}
if($i%7==0){
echo'</tr><tr>';
}
}
echo'</tr>';
}
privatefunctionshowChangeDate()
{
$url=basename($_SERVER['PHP_SELF']);
echo'<tr>';
echo'<td><ahref="?'.$this->preYearUrl($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->preMonthUrl($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdn="3"><form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($ye=1970;$ye<=2038;$ye++){
$selected=($ye==$this->year)?'selected':'';
echo'<option'.$selected.'value="'.$ye.'">'.$ye.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value+''">';
for($mo=1;$mo<=12;$mo++){
$selected=($mo==$this->month)?'selected':'';
echo'<option'.$selected.'value="'.$mo.'">'.$mo.'</option>';
}
echo'</select>';
echo'</form></td>';
echo'<td><ahref="?'.$this->nextMonthUrl($this->year,$this->month).'">'.'>'.'</a></td>';
echo'<td><ahref="?'.$this->nextYearUrl($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'</tr>';
}
privatefunctionpreYearUrl($year,$month)
{
$year=($this->year<=1970)?1970:$year-1;
return'year='.$year.'&month='.$month;
}
privatefunctionnextYearUrl($year,$month)
{
$year=($year>=2038)?2038:$year+1;
return'year='.$year.'&month='.$month;
}
privatefunctionpreMonthUrl($year,$month)
{
if($month==1){
$month=12;
$year=($year<=1970)?1970:$year-1;
}else{
$month--;
}
return'year='.$year.'&month='.$month;
}
privatefunctionnextMonthUrl($year,$month)
{
if($month==12){
$month=1;
$year=($year>=2038)?2038:$year+1;
}else{
$month++;
}
return'year='.$year.'&month='.$month;
}
}調(diào)用方法
代碼如下復(fù)制代碼<?php
$params=array();
if(isset($_GET['year'])&&isset($_GET['month'])){
$params=array(
'year'=>$_GET['year'],
'month'=>$_GET['month'],
);
}
$params['url']
='demo.php';
require_once'calendar.class.php';
?><html>
<head>
<title>日歷demo</title>
<metahttp-equiv="Content-Type"content="text/html"charset="UTF-8"/>
<styletype="text/css">
table.calendar{
border:1pxsolid#050;
}
.calendarth,.calendartd{
width:30px;
text-align:center;
}
.calendarth{
background-color:#050;
color:#fff;
}
.today{
color:#fff;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 深度閱讀名著閱讀的進(jìn)階技巧
- 醫(yī)療護(hù)理醫(yī)學(xué)培訓(xùn) 支氣管哮喘的治療原則課件
- 2023八年級物理下冊 第十二章 機(jī)械能第3節(jié) 水能和風(fēng)能說課稿 (新版)教科版
- 七年級地理下冊 第七章 第二節(jié) 東南亞說課稿1 (新版)新人教版
- 用戶體驗(yàn)與用戶心理的關(guān)聯(lián)研究
- 現(xiàn)代物流行業(yè)的創(chuàng)新管理與市場機(jī)遇分析
- 現(xiàn)代城市雕塑與城市文化的互生關(guān)系
- 現(xiàn)代城市文化公園的智慧化管理與服務(wù)策略
- 現(xiàn)代化分析方法在中藥制藥工業(yè)的應(yīng)用
- 二零二五年度2025年度道路路面施工安全協(xié)議
- 欠薪證明協(xié)議書(2篇)
- 竣工驗(yàn)收要點(diǎn)培訓(xùn)課件
- 注射泵操作使用課件
- 自愿參加活動(dòng)免責(zé)申明
- 2024年全國新高考1卷(新課標(biāo)Ⅰ)數(shù)學(xué)試卷(含答案詳解)
- 人教版高中生物學(xué)新舊教材知識(shí)差異盤點(diǎn)
- 字體設(shè)計(jì)(上海出版印刷高等??茖W(xué)校) 知到智慧樹網(wǎng)課答案
- 大連高新區(qū)整體發(fā)展戰(zhàn)略規(guī)劃(產(chǎn)業(yè)及功能布局)
- 中國行政區(qū)域劃分一覽表
- 智慧農(nóng)業(yè)技術(shù)助力農(nóng)業(yè)精細(xì)化管理
- 腫瘤科放射防護(hù)課件
評論
0/150
提交評論