<?php
//修改頁面編碼
header("content-type: text/html; charset=utf-8");
//如果沒有傳入年份則獲取當前系統年份
$year=!isset($_get['y'])?$_get['y']:date('y');
//如果沒有傳入月份則獲取當前系統月份
$month=$_get['m']?$_get['m']:date('m');
//獲取當前月有多少天
$days=date('t',strtotime("--1"));
//當前1號是星期幾
$week=date('w',strtotime("--1"));
//輸出表頭
echo
""; echo
""; //輸出日期**
echo
""; echo
""; echo
"週日";
echo
"周一";
echo
"周二";
echo
"週三";
echo
"周四";
echo
"周五";
echo
"週六";
echo
""; //鋪**
for($i=1-$week;$i
<=$days;)else";
}$i++;
}echo
""; }
echo
""; //實現上一月和上一年
if($month==1)else
//實現下一月和下一年
if($month==12)else
echo
"上個月";
echo
"下個月";
echo
"";?>
1、啟動執行環境,在這裡我使用的是phpstudy.
注:儲存路徑為phpstudy的www目錄下,這個在上一月、下一月中的實現中路徑很重要。
2、在瀏覽器輸入url,比如http://localhost/day.php?y=2016&m=6
注:可在位址中傳入年(y)、月(m)引數
3、測試結果:
PHP實現簡單萬年曆
header content type text html charset utf 8 例項 萬年曆案例 需求 1 幾年 幾月 幾日 2 週日 週六 3 一號是星期幾 4 這個月有多少天 echo 獲取當前年 year get y get y date y 獲取當前月 month get m get...
php萬年曆原型
計算當月天數 days date t strtotime 2017 11 1 w date w strtotime 2017 11 1 firstday 1 w 星期日星期一 星期二星期三 星期四星期五 星期六 for i firstday i days else i echo 以下部分是在tp框架...
PHP製作萬年曆
預覽圖 當前時間為2018年9月13日 首先要了解php對日期時間的處理 1.主要的三個函式 2.首先先寫個html標籤,再在body標籤裡面插入php header content type text html charset utf 8 檢測使用者是否提交資料 if isset post yea...