从周一开始使用正确的ColSpan启动PHP日历

从周一开始使用正确的ColSpan启动PHP日历,php,calendar,Php,Calendar,我试图修改一个在线PHP日历代码,从周一开始,而不是周日 在PHP中返回时,我需要日历位于以下数组中: 周一,周二,周三,周四,周五 周日开始,效果不错,但我想调整一下 我自己也试过了,但这是超出我能力范围的一点建议。非常感谢您的帮助 function build_calendar($month,$year,$hide) { // Create array containing abbreviations of days of week. $daysOfWeek = arra

我试图修改一个在线PHP日历代码,从周一开始,而不是周日

在PHP中返回时,我需要日历位于以下数组中:

周一,周二,周三,周四,周五

周日开始,效果不错,但我想调整一下

我自己也试过了,但这是超出我能力范围的一点建议。非常感谢您的帮助

function build_calendar($month,$year,$hide) 
{

    // Create array containing abbreviations of days of week.
    $daysOfWeek = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');

    // 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 = '';

    if ($hide == true) {
        $calendar .= "<div class='date_picker' style='display:none;' data-month='".$month."'>";
        $calendar .= "<div class='date_picker__wrap'>";
        $calendar .= "<a class='date_picker--prev'>Previous</a>";
        $calendar .= "<h2>$monthName, $year</h2>";
        $calendar .= "<a class='date_picker--next'>Next</a>";
        $calendar .= "</div>";
        $calendar .= "<table class='table table-bordered table-hover date_picker__calendar'>";
    } else {
        $calendar .= "<div class='date_picker date_picker__current' data-month='".$month."'>";
        $calendar .= "<div class='date_picker__wrap'>";
        $calendar .= "<a class='date_picker--prev'>Previous</a>";
        $calendar .= "<h2>$monthName, $year</h2>";
        $calendar .= "<a class='date_picker--next'>Next</a>";
        $calendar .= "</div>";
        $calendar .= "<table class='table table-bordered table-hover date_picker__calendar'>";
    }

    $calendar .= "<tr>";

    // Create the calendar headers

    foreach($daysOfWeek as $day) {
         $calendar .= "<th class='header'>$day</th>";
    } 

    // Create the rest of the calendar

    // Initiate the day counter, starting with the 1st.
    $currentDay = 1;

    $calendar .= "</tr><tr>";

    // The variable $dayOfWeek is used to
    // ensure that the calendar
    // display consists of exactly 7 columns.

    if ($dayOfWeek > 0) { 
         $calendar .= "<td style='background: #f9f9f9;' colspan='$dayOfWeek'>&nbsp;</td>"; 
    }

    $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 .= "</tr><tr>";

      }

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

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

      if (date('d') == $currentDay && date('n') == $month) {
           $add_class = ' today';
      } else {
           $add_class = '';
      }

      if (date('d') > $currentDay && date('n') == $month) {
           $add_class .= ' disable';
      }

      if ($dayOfWeek == 6 || $dayOfWeek == 0) {
           $calendar .= "<td class='day weekend".$add_class."' data-date='$date'><span class='actual_day'>$currentDay</span><span class='price'>+£50</span></td>";
      } else {
           $calendar .= "<td class='day weekday".$add_class."' data-date='$date'><span class='actual_day'>$currentDay</span><span class='price'>-£50</span></td>";
      };

      // Increment counters

      $currentDay++;
      $dayOfWeek++;

    }

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

    if ($dayOfWeek != 7) { 

         $remainingDays = 7 - $dayOfWeek;
         $calendar .= "<td style='background: #f9f9f9;' colspan='$remainingDays'>&nbsp;</td>"; 

    }

    $calendar .= "</tr>";
    $calendar .= "</table>";
    $calendar .= "</div>";

    return $calendar;
function build\u日历($month、$year、$hide)
{
//创建包含周中天数缩写的数组。
$daysOfWeek=数组('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
//这个月的第一天是什么时候?
$firstDayOfMonth=mktime(0,0,0,$month,1,$year);
//这个月有多少天?
$numberDays=日期('t',$firstDayOfMonth);
//检索有关活动第一天的一些信息
//有问题的月份。
$dateComponents=getdate($firstDayOfMonth);
//这个月的名字是什么?
$monthName=$dateComponents['month'];
//第一天的指数值(0-6)是多少
//有问题的月份。
$dayOfWeek=$dateComponents['wday'];
//创建表格标记开始符和日期标题
$calendar='';
如果($hide==true){
$calendar.=“”;
$calendar.=“”;
$calendar.=“上一次”;
$calendar.=“$monthName,$year”;
$calendar.=“下一步”;
$calendar.=“”;
$calendar.=“”;
}否则{
$calendar.=“”;
$calendar.=“”;
$calendar.=“上一次”;
$calendar.=“$monthName,$year”;
$calendar.=“下一步”;
$calendar.=“”;
$calendar.=“”;
}
$calendar.=“”;
//创建日历标题
foreach($daysOfWeek作为$day){
$calendar.=“$day”;
} 
//创建日历的其余部分
//启动日计数器,从1开始。
$currentDay=1;
$calendar.=“”;
//变量$dayOfWeek用于
//确保日历
//显示内容正好由7列组成。
如果($dayOfWeek>0){
$calendar.=“”;
}
$month=str_pad($month,2,“0”,str_pad_左);
而($currentDay$currentDay&&date('n')==$month){
$add_class.='disable';
}
如果($dayOfWeek==6 | |$dayOfWeek==0){
$calendar.=“$currentDay+50英镑”;
}否则{
$calendar.=“$currentDay-$50”;
};
//增量计数器
$currentDay++;
$dayOfWeek++;
}
//如有必要,填写本月最后一周的行
如果($dayOfWeek!=7){
$remainingDays=7-$dayOfWeek;
$calendar.=“”;
}
$calendar.=“”;
$calendar.=“”;
$calendar.=“”;
返回$calendar;

我自己设法解决了这个问题:

    function build_calendar($month,$year,$hide) 
{

    // Create array containing abbreviations of days of week.
    $daysOfWeek = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');

    // 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'] - 1;

    // Create the table tag opener and day headers
    $calendar = '';

    if ($hide == true) {
        $calendar .= "<div class='date_picker' style='display:none;' data-month='".$month."'>";
        $calendar .= "<div class='date_picker__wrap'>";
        $calendar .= "<a class='date_picker--prev'>Previous</a>";
        $calendar .= "<h2>$monthName, $year</h2>";
        $calendar .= "<a class='date_picker--next'>Next</a>";
        $calendar .= "</div>";
        $calendar .= "<table class='table table-bordered table-hover date_picker__calendar'>";
    } else {
        $calendar .= "<div class='date_picker date_picker__current' data-month='".$month."'>";
        $calendar .= "<div class='date_picker__wrap'>";
        $calendar .= "<a class='date_picker--prev'>Previous</a>";
        $calendar .= "<h2>$monthName, $year</h2>";
        $calendar .= "<a class='date_picker--next'>Next</a>";
        $calendar .= "</div>";
        $calendar .= "<table class='table table-bordered table-hover date_picker__calendar'>";
    }

    $calendar .= "<tr>";

    // Create the calendar headers

    foreach($daysOfWeek as $day) {
         $calendar .= "<th class='header'>$day</th>";
    } 

    // Create the rest of the calendar

    // Initiate the day counter, starting with the 1st.
    $currentDay = 1;

    $calendar .= "</tr><tr>";

    // The variable $dayOfWeek is used to
    // ensure that the calendar
    // display consists of exactly 7 columns.

    if ($dayOfWeek > 0) {
         $calendar .= "<td style='background: #f9f9f9;' colspan='$dayOfWeek'>&nbsp;</td>"; 
    }

    if ($dayOfWeek == -1) {
      $calendar .= "<td style='background: #f9f9f9;' colspan='6'>&nbsp;</td>"; 
    }

    $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) {

           $dayOfWeek = 0;
           $calendar .= "</tr><tr>";

      }

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

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

      if (date('d') == $currentDay && date('n') == $month) {
           $add_class = ' today';
      } else {
           $add_class = '';
      }

      if (date('d') > $currentDay && date('n') == $month) {
           $add_class .= ' disable';
      }

      if ($dayOfWeek == 5 || $dayOfWeek == 6) {
           $calendar .= "<td class='day weekend".$add_class."' data-date='$date' data-week='$dayOfWeek'><span class='actual_day'>$currentDay</span><span class='price'>+£50</span></td>";
      } else {
           $calendar .= "<td class='day weekday".$add_class."' data-date='$date' data-week='$dayOfWeek'><span class='actual_day'>$currentDay</span><span class='price'>-£50</span></td>";
      };

      // Increment counters

      $currentDay++;
      $dayOfWeek++;

    }

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

    if ($dayOfWeek != 7) { 

         $remainingDays = 7 - $dayOfWeek;
         $calendar .= "<td style='background: #f9f9f9;' colspan='$remainingDays'>&nbsp;</td>"; 

    }

    $calendar .= "</tr>";
    $calendar .= "</table>";
    $calendar .= "</div>";

    return $calendar;
function build\u日历($month、$year、$hide)
{
//创建包含周中天数缩写的数组。
$daysOfWeek=数组('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
//这个月的第一天是什么时候?
$firstDayOfMonth=mktime(0,0,0,$month,1,$year);
//这个月有多少天?
$numberDays=日期('t',$firstDayOfMonth);
//检索有关活动第一天的一些信息
//有问题的月份。
$dateComponents=getdate($firstDayOfMonth);
//这个月的名字是什么?
$monthName=$dateComponents['month'];
//第一天的指数值(0-6)是多少
//有问题的月份。
$dayOfWeek=$dateComponents['wday']-1;
//创建表格标记开始符和日期标题
$calendar='';
如果($hide==true){
$calendar.=“”;
$calendar.=“”;
$calendar.=“上一次”;
$calendar.=“$monthName,$year”;
$calendar.=“下一步”;
$calendar.=“”;
$calendar.=“”;
}否则{
$calendar.=“”;
$calendar.=“”;
$calendar.=“上一次”;
$calendar.=“$monthName,$year”;
$calendar.=“下一步”;
$calendar.=“”;
$calendar.=“”;
}
$calendar.=“”;
//创建日历标题
foreach($daysOfWeek作为$day){
$calendar.=“$day”;
} 
//创建日历的其余部分
//启动日计数器,从1开始。
$currentDay=1;
$calendar.=“”;
//变量$dayOfWeek用于
//确保日历
//显示内容正好由7列组成。
如果($dayOfWeek>0){
$calendar.=“”;
}
如果($dayOfWeek==-1){
$calendar.=“”;
}
$month=str_pad($month,2,“0”,str_pad_左);
而($currentDay$currentDay&&date('n')==$month){
$add_class.='disable';
}
如果($dayOfWeek==5 | |$dayOfWeek==6){
$calendar.=“$currentDay+50英镑”;
}否则{
$calendar.=“$currentDay-$50”;
};
//增量计数器
$currentDay++;
$dayOfWeek++;
}
//如有必要,填写本月最后一周的行
如果($dayOfWeek!=7){
$remainingDays=7-$dayOfWeek;
$calendar.=“”;
}
$calendar.=“”;
$calendar.=“”;
$calendar.=“”;
返回$calendar;
}