日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php如何生成一年的日历表_PHP简单创建日历的方法

發布時間:2024/3/26 php 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php如何生成一年的日历表_PHP简单创建日历的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了PHP簡單創建日歷的方法。分享給大家供大家參考,具體如下:

function build_calendar($month,$year) {

// Create array containing abbreviations of days of week.

$daysOfWeek = array('S','M','T','W','T','F','S');

// What is the first day of the month in question?

$firstDayOfMonth = mktime(0,0,0,$month,1,$year);

// How many days does this month contain?

$numberDays = date('t',$firstDayOfMonth);

// Retrieve some information about the first day of the

// month in question.

$dateComponents = getdate($firstDayOfMonth);

// What is the name of the month in question?

$monthName = $dateComponents['month'];

// What is the index value (0-6) of the first day of the

// month in question.

$dayOfWeek = $dateComponents['wday'];

// Create the table tag opener and day headers

$calendar = "

$calendar .= "

$monthName $year";

$calendar .= "

";

// Create the calendar headers

foreach($daysOfWeek as $day) {

$calendar .= "

$day";

}

// Create the rest of the calendar

// Initiate the day counter, starting with the 1st.

$currentDay = 1;

$calendar .= "

";

// The variable $dayOfWeek is used to

// ensure that the calendar

// display consists of exactly 7 columns.

if ($dayOfWeek > 0) {

$calendar .= "

?";

}

$month = str_pad($month, 2, "0", STR_PAD_LEFT);

while ($currentDay <= $numberDays) {

// Seventh column (Saturday) reached. Start a new row.

if ($dayOfWeek == 7) {

$dayOfWeek = 0;

$calendar .= "

";

}

$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);

$date = "$year-$month-$currentDayRel";

$calendar .= "

$currentDay";

// Increment counters

$currentDay++;

$dayOfWeek++;

}

// Complete the row of the last week in month, if necessary

if ($dayOfWeek != 7) {

$remainingDays = 7 - $dayOfWeek;

$calendar .= "

?";

}

$calendar .= "

";

$calendar .= "

";

return $calendar;

}

//調用方法

echo build_calendar(05,2016);

?>

運行結果如下圖所示:

關于在線顯示日期還可參考本站在線工具:

希望本文所述對大家PHP程序設計有所幫助。

總結

以上是生活随笔為你收集整理的php如何生成一年的日历表_PHP简单创建日历的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。