導航:首頁 > 編程語言 > php日歷源碼

php日歷源碼

發布時間:2022-09-27 03:23:28

A. 如何用php製作日歷

calendar.class.php
代碼如下:
<?php
classCalendar{
private$year;//當前的年
private$month;//當前的月
private$start_weekday;//當月的第一天對應的是周幾
private$days;//當前月一共多少天

function__construct(){
$this->year=isset($_GET["year"])?$_GET["year"]:date("Y");
$this->month=isset($_GET["month"])?$_GET["month"]:date("m");

$this->start_weekday=date("w",mktime(0,0,0,$this->month,1,$this->year));
$this->days=date("t",mktime(0,0,0,$this->month,1,$this->year));
}

functionout(){
echo'<tablealign="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo'</table>';
}

privatefunctionweeksList(){
$week=array('日','一','二','三','四','五','六');

echo'<tr>';
for($i=0;$i<count($week);$i++)
echo'<thclass="fontb">'.$week[$i].'</th>';

echo'</tr>';
}

privatefunctiondaysList(){
echo'<tr>';
//輸出空格(當前一月第一天前面要空出來)
for($j=0;$j<$this->start_weekday;$j++)
echo'<td></td>';


for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d'))
echo'<tdclass="fontb">'.$k.'</td>';
else
echo'<td>'.$k.'</td>';

if($j%7==0)
echo'</tr><tr>';

}

//後面幾個空格
while($j%7!==0){
echo'<td></td>';
$j++;
}

echo'</tr>';
}

privatefunctionprevYear($year,$month){
$year=$year-1;

if($year<1970)
$year=1970;

return"year={$year}&month={$month}";
}


privatefunctionprevMonth($year,$month){
if($month==1){
$year=$year-1;

if($year<1970)
$year=1970;

$month=12;
}else{
$month--;
}

return"year={$year}&month={$month}";
}


privatefunctionnextYear($year,$month){
$year=$year+1;

if($year>2038)
$year=2038;

return"year={$year}&month={$month}";
}


privatefunctionnextMonth($year,$month){
if($month==12){
$year++;

if($year>2100)
$year=2100;

$month=1;
}else{
$month++;
}


return"year={$year}&month={$month}";
}

privatefunctionchageDate($url=""){
echo'<tr>';
echo'<td><ahref="?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdcolspan="3">';
echo'<form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($sy=1970;$sy<=2100;$sy++){
$selected=($sy==$this->year)?"selected":"";
echo'<option'.$selected.'value="'.$sy.'">'.$sy.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
echo'<option'.$selected1.'value="'.$sm.'">'.$sm.'</option>';
}
echo'</select>';
echo'</form>';
echo'</td>';


echo'<td><ahref="?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'<td><ahref="?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
echo'</tr>';
}

}
?>test.php

代碼如下:
<style>
table{
border:1pxsolid#050;
}

.fontb{
color:white;
background:blue;
}


th{
width:30px;
}

td,th{
height:30px;
text-align:center;

}
form{
margin:0px;
padding:0px;
}
</style>
<?php
include"calendar.class.php";

$calendar=newCalendar;

$calendar->out();
?>

B. php小白,做的日歷有源碼,求大神幫看看問題在哪裡,感激不盡

代碼邏輯就有問題

你的sql循環遍歷里截取了一次day應該是無用代碼,下面把數據存入數組中寫的鍵名 data 和前面寫的date並不一樣。你自己檢查一下有沒有問題。

另外 你的判斷日期是否特殊日期的邏輯里,是根據數組索引 $i 來判斷的,你能保證從資料庫取出的數據是按天排序每天都有的嗎?

一般做日期判斷可以把數據拉出來按日期索引 ,這樣後面日期判斷的時候根據鍵名來判斷就比較准確了。

//存入標志數組
$day_color[$row['date']]=true;

for(...){
$date=sprintf("%02d",$i);
if(!empty($day_color['2019-01-'.$date])){
...
}else{
...
}
}

C. 求助:關於php製作日歷的問題

$php_self?year=$y_lnk1&month=$month中的$php_self是鏈接地址,這里給出的是一個變數來代替冗長的字元串,比如說www.phpfans.net,問號後面的year、month傳的參數,並分別給他們賦值為$y-lnk、$month。
添加該鏈接出錯是語法錯誤!將雙引號去掉即可。

D. php中將一年12個月的日歷全部輸出。如何做

<?php
//SKY8G提供
function cal_days_in_year($year){
$days=0;
for($month=1;$month<=12;$month++){
$days = $days + cal_days_in_month(CAL_GREGORIAN,$month,$year);
}
return $days;
}
//閏年
echo "這是閏年一年有:".cal_days_in_year(2000)."天";
echo "\n";
//平年
echo "這是平年一年有:".cal_days_in_year(1999)."天";
echo "\n";
//2019年
echo "今年2019年有:".cal_days_in_year(date('Y',time()))."天";
echo "\n";
//接下來我們是用php的內置函數cal_days_in_month()
$d=cal_days_in_month(CAL_GREGORIAN,2,2010);
echo "2010 年平年 2 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,2,2000);
echo "2000 年閏年 2 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2010);
echo "2010 年平年 4 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2000);
echo "2000 年閏年 4 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2010);
echo "2010 年平年 8 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2000);
echo "2000 年閏年 8 月有 $d 天。";
//詳情如果想了解詳情去sky8g網觀看,希望對你有幫助!

E. 用php編程按月顯示的日歷

我把我寫的分享給你吧

/**
*顯示日歷
*@paramint$time時間戳
*/
privatefunction__calendarPanel($time=null){
$time||$time=time();
$dateinfo=getdate($time);
$calendar=array(
'year'=>$dateinfo['year'],
'month'=>$dateinfo['mon'],
'day'=>$dateinfo['mday'],
);
$m_start=strtotime(date('Y-m-01',$time));//本月第一天
$m_start_w=get_week($m_start,true);//本月第一天星期索引,0表示星期日
$m_end=strtotime('+1month',$m_start)-86400;//本月最後一天
$m_end_w=get_week($m_end,true);//本月最後一天星期索引,0表示星期日
//補齊上月日期
for($i=0;$i<$m_start_w;$i++){
$calendar['days'][]=array(
'style'=>'bef_month',
'day'=>abs(date('d',$m_start-($m_start_w-$i)*86400)),
);
}
//本月日期
for($i=$m_start;$i<=$m_end;$i+=86400){
$calendar['days'][]=array(
'style'=>'the_month'.(date('d',$i)==$calendar['day']?"bold":""),
'day'=>abs(date('d',$i)),
);
}
//補齊下月日期
for($i=$m_end_w+1;$i<=6;$i++){
$calendar['days'][]=array(
'style'=>'aft_month',
'day'=>abs(date('d',$m_end+($i-$m_end_w)*86400)),
);
}
return$calendar;
}




日歷都存到返回的一個數組里了,你列印的時候,一行放7列,第一列星期日

F. php初學者,做了一個簡易日歷,如果要跳轉到指定日期的話用的是地址欄傳參。。現在我想添加幾個按鈕

可以通過php寫href的值啊,

<?php
$year=(int)$_GET['year'];
echo'<ahref="index,php?year='.($year+1).'">NextYear</a>';
?>

G. php中 點擊輸入框即跳出一個日歷··如何做到

jQuery 的插件 Datepicker
這是一個非常優秀又實用的日期選擇器插件,是基於Jquery開發的,您只需要將Jquery庫和該插件文件導入到您的頁面中,而使用很少的代碼就能夠為您完成非常好的效果出來!非常推薦哦! 這是一個非常優秀又實用的日期選擇器插件,是基於Jquery開發的,您只需要將Jquery庫和該插件文件導入到您的頁面中,而使用很少的代碼就能夠為您完成非常好的效果出來!

H. php日歷插件的製作方法,求思路

<?phpheader("content-type:text/html;charset=utf-8");?>
<?php?>
<tableclass="tabletable-stripedtable-hover">
<?php
//註:32位機器或者32位PHP版本可能只能計算到2038年之前的月份
//若沒有GET方法傳入參數,則使用伺服器本地當前日期;否則使用傳入的參數,方便跳轉月份
$year=date("Y");
$month=date("n");
$alert="<divclass='alertalert-warning'>輸入的日期格式有誤!</div>";
$alertYear="<divclass='alertalert-warning'>無法計算1901年以前的日歷!</div>";
if($_REQUEST){
$year=$_REQUEST["year"];
$month=$_REQUEST["month"];
}
if(!in_array($month,array("1","2","3","4","5","6","7","8","9","10","11","12"))){echo$alert;exit;}
if($year<1901){echo$alertYear;exit;}
?>
<caption><h4><?phpecho$year;?>&nbsp;年&nbsp;<?phpecho$month;?>&nbsp;月</h4></caption>
<?php
//計算當前日期,當月天數,獲得星期數據,將默認星期天數字0改為7,方便處理循環
$today=date("j");
$days=date("t",strtotime("$year-$month-01"));
$week=date("w",strtotime("$year-$month-01"));
if($week==0){$week=7;}
?>
<tr>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
<th>日</th>
</tr>
<tr>
<?php
//插入空白無日期區域,循環次數為當前月第一天的星期數-1
for($space=1;$space<$week;$space++){
echo"<td>-</td>";
}
//循環插入數據,當到達周日時換行輸出;標記當前日期為紅色
for($day=1;$day<=$days;$day++){
if(($day+$week-1)%7===0){
if($day==$today&&$year==date("Y")&&$month==date("n")){
echo"<tdstyle='background-color:pink;'>$day</td>";
echo"</tr>";
echo"<tr>";
}
echo"<td>$day</td>";
echo"</tr>";
echo"<tr>";
}else{
if($day==$today&&$year==date("Y")&&$month==date("n")){
echo"<tdstyle='background-color:pink;'>$day</td>";
}else{
echo"<td>$day</td>";
}
}
}
//尾部補足
$spacing=36-$days-$week<0?43-$days-$week:36-$days-$week;
for($footer=1;$footer<=$spacing;$footer++){
echo"<td>-</td>";
}
?>
</tr>
</table>

我以前寫的,你隨意看看~~

閱讀全文

與php日歷源碼相關的資料

熱點內容
泰國人妖電影。 瀏覽:697
flaskweb開發pdf 瀏覽:139
一部裸著參加聚會的電影名是什麼 瀏覽:412
微黃的小說 瀏覽:694
召氏四級片 瀏覽:360
舞陽電影院今天什麼電影 瀏覽:503
最近上映的電影視頻網址 瀏覽:370
酒吧2021在線觀看 瀏覽:878
歐美同性大尺度電影 瀏覽:798
如何練習解壓 瀏覽:392
國外一部關於兒子跟後媽的叫什麼流浪的電影 瀏覽:906
免費電影鬼片 瀏覽:170
男主姓傅的小說 瀏覽:661
大胸部的女人電影 瀏覽:24
劉德華返老還童的電影叫什麼 瀏覽:264
羅莎卡拉喬洛 bodyguard 瀏覽:964
金玉王朝完整番外txt 瀏覽:558
需要錢觀看的網站 瀏覽:23
不可能的世界小說免費看 瀏覽:744
3d左右分屏電影網站 瀏覽:378