在下拉框中显示日历周

Diplay Calendar Weeks in Dropdown-Box

我写了一个小脚本,但不太明白为什么它不起作用。我想在下拉框中显示所有日历周(通常每年 52 周)!我在网上没有找到类似的脚本,所以我自己试了一下。谁能告诉我我做错了什么?

我只看到一个空的下拉框!如果有人可以帮助我,那就太好了。写那部分代码花了我一段时间。

编辑:

我的职能:

<?php
function weekDayToTime($week, $year, $dayOfWeek = 1) {
  //dayOfWeek: 0=sunday, 1=monday, ..., 6=saturday
  $dayOfWeekRef = date("w", mktime (0,0,0,1,4,$year));
  if ($dayOfWeekRef == 0) $dayOfWeekRef = 7;
  $resultTime = mktime(0,0,0,1,4,$year) + ((($week - 1) * 7 + ($dayOfWeek - $dayOfWeekRef)) * 86400);
  $resultTime = cleanTime($resultTime);  //Cleaning daylight saving time hours
  return $resultTime;
};

function cleanTime($time) {
  //This function strips all hours, minutes and seconds from time.
  //For example useful of cleaning up DST hours from time
  $cleanTime = mktime(0,0,0,date("m", $time),date("d", $time),date("Y", $time));
  return $cleanTime;
} 

function weeks($year)
                { 
return date("W",mktime(0,0,0,12,28,$year));
} 
?>

<?php


            $year = date("Y");

            echo "<form method='GET' action='index.php'>"."<select name='w' onChange='this.form.submit()'>";
for($i=1;$i<=weeks($year);$i++)
{


$start = weekDayToTime($i, $year);
$end   = cleanTime(604800 + $start);

    if(weekDayToTime(date("W"), date("Y")) == $start)
    {
        $selected = "selected = 'selected' /";
    }
    else
    {
        $selected = '/';
    }

echo "<option value='".$i."' $selected>KW ".$i.": ".strftime("%d. %B %Y", $start)." bis ".strftime("%d. %B %Y", $end)."</option>";  
}
echo "</select>"."<input type='hidden' name='y' value='".$year."' />"."</form>"; 

?>

谢谢, 克里斯

    1 <?php
    2 function weekDayToTime($week, $year, $dayOfWeek = 1) {
    3     $dayOfWeekRef = date("w", mktime (0,0,0,1,4,$year));
    4     if ($dayOfWeekRef == 0) $dayOfWeekRef = 7;
    5     $resultTime = mktime(0,0,0,1,4,$year) + ((($week - 1) * 7 + ($dayOfWeek - $dayOfWeekRef)) * 86400);
    6     $resultTime = cleanTime($resultTime);  //Cleaning daylight saving time hours
    7     return $resultTime;
    8 };  
    9   
   10 function cleanTime($time) {
   11     //This function strips all hours, minutes and seconds from time.
   12     //For example useful of cleaning up DST hours from time
   13     $cleanTime = mktime(0,0,0,date("m", $time),date("d", $time),date("Y", $time));
   14     return $cleanTime;
   15 }   
   16 function weeks($year)
   17 {   
   18     return date("W",mktime(0,0,0,12,28,$year));
   19 }   
   20 
   21 $year = date("Y");
   22 echo('year is ' . var_export($year, true));
   23 echo('weeks is ' . var_export(weeks($year), true));
   24 
   25 echo "<form method='GET' action='index.php'>"."<select name='w' onChange='this.form.submit()'>";
   26 for($i=1;$i<=weeks($year);$i++) {
   27 
   28 
   29     $start = weekDayToTime($i, $year);
   30     $end   = cleanTime(604800 + $start);
   31 
   32     if(weekDayToTime(date("W"), date("Y")) == $start) {
   33         $selected = "selected = 'selected'";
   34     } else {
   35         $selected = '';
   36     }
   37 
   38     echo "<option value='".$i."' $selected>KW ".$i.": ".strftime("%d. %B %Y", $start)." bis ".strftime("%d. %B %Y", $end)."</option> \n";
   39 }
   40 echo "</select>"."<input type='hidden' name='y' value='".$year."' />"."</form> \n";
   41 
   42 ?>

这是我的代码版本,似乎工作正常,我唯一更改的是从 $selected 中删除斜杠,以便没有自关闭选项标签。会不会是这样?