當前位置:首頁 » 編程語言 » php日歷

php日歷

發布時間: 2022-01-10 01:32:26

1. 用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列,第一列星期日

2. 如何用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();
?>

3. PHP萬年歷

出門右轉,好走不送

4. 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網觀看,希望對你有幫助!

5. php項目 日歷

PHP 日歷實現代碼
<?php
$monthoneday=date("Ym")."01";
$oneweekday=date("w",strtotime($monthoneday)); //獲得本月1號星期幾
$monthday=date("t"); //本月多少天
$startlow=($oneweekday==0)?7:$oneweekday; //從第幾列開始
for($a=1,$b=$startlow;$a<=$monthday;$a++,$b++){
$ary[$b]=$a; //用數組控制日期在哪裡輸出
}
$c=1;
//輸出行數等於當月天數除7取整再加1
for($a=1;$a<=(int)($monthday/7)+1;$a++){
echo "<tr>";
//用數組的key來控制輸出
for($b=1;$b<=7;$b++,$c++){
if($ary[$c]==date("j")){
echo '<td id="today">';
}else{
echo "<td>";
}
echo $ary[$c];
echo "</td>";
echo "\n";
}
echo "</tr>";
}
?>
參考文獻http://bbs.hounwang.com/

6. 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>

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

7. php怎麼做日歷

sybase_connect連上資料庫
語法: int sybase_connect(string [servername], string [username], string [password]);
返回值: 整數函數種類: 資料庫功能 本函數用來打開與 Sybase 資料庫的連接。
參數 servername 為欲連上的資料庫伺服器名稱。
參數 username 及 password 可省略,分別為連接使用的帳號及密碼。
使用本函數需注意早點關閉資料庫,以減少系統的負擔。
連接成功則返回資料庫的連接代號,失敗返回 false 值。

8. HTML5+PHP要怎麼製作日歷

JS有個dataPicker控制項,如果是自己來做需要寫循環判斷演算法

9. 製作一個php代碼要求是實現日歷功能

PHP寫的日歷代碼,網上有很多,有簡單也有復雜的,具體的代碼要看你的需要來確定。

考慮到做課題的話,個人推薦使用《PHP經典實例》一書中第3章最後一節,有個完整的 日歷 的代碼,建議你可以拿來參考,並且建議將該書第3章的內容都看一下。

《PHP經典實例》網上有電子版。

熱點內容
單片機android 發布:2024-09-20 09:07:24 瀏覽:760
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:661
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:308
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:286
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:814
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:160
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:91
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:505
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:655
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:479