Php 我想在日历中添加日期名称
我想用$day_num加上$day_of_week,但我得到了一些奇怪的组合(1周二2 Tuf 3拖船4 Tuh 5 Tui 6 Tuj 7 Tuk 8 Tul 9 Tum 10 Tun 11 Tuo 12 Tup) 日历上不再显示1 Tue 2 Tuf 3拖船等。我把它拿出来了 我希望日历看起来像这样(1周一2周二3周三4周四5周五6周六7周日) 这是导致问题的代码部分Php 我想在日历中添加日期名称,php,Php,我想用$day_num加上$day_of_week,但我得到了一些奇怪的组合(1周二2 Tuf 3拖船4 Tuh 5 Tui 6 Tuj 7 Tuk 8 Tul 9 Tum 10 Tun 11 Tuo 12 Tup) 日历上不再显示1 Tue 2 Tuf 3拖船等。我把它拿出来了 我希望日历看起来像这样(1周一2周二3周三4周四5周五6周六7周日) 这是导致问题的代码部分 //count up the days, untill we've done all of them in the mont
//count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month )
{
echo "<td> $day_num $day_of_week </td>";
$day_num++;
$day_count++;
$day_of_week++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//计算天数,直到我们在一个月内完成所有工作
而($day_num 7)
{
回声“;
$day_count=1;
}
}
这是完整的代码,没有上面的修改
<?php
//This gets today's date
$date =time () ;
//This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;
//This gets us the month name
$title = date('F', $first_day) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day) ;
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;
//Here we start building the table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td
width=42>T</td><td width=42>W</td><td width=42>T</td><td
width=42>F</td><td width=42>S</td></tr>";
//This counts the days in the week, up to 7
$day_count = 1;
echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month )
{
echo "<td> $day_num </td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
echo "</tr></table>";
?>
正如我所指出的,这部分需要有一个
mtkime()
计算:
//count up the days, until we've done all of them in the month
while ( $day_num <= $days_in_month ) {
echo "<td> $day_num ".date("D",mktime(0,0,0,$month,$day_num,$year))."</td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7) {
echo "</tr><tr>";
$day_count = 1;
}
}
//计算天数,直到我们在一个月内完成所有工作
而($day_num 7){
回声“;
$day_count=1;
}
}
正如我所指出的,这部分需要有一个mtkime()
计算:
//count up the days, until we've done all of them in the month
while ( $day_num <= $days_in_month ) {
echo "<td> $day_num ".date("D",mktime(0,0,0,$month,$day_num,$year))."</td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7) {
echo "</tr><tr>";
$day_count = 1;
}
}
//计算天数,直到我们在一个月内完成所有工作
而($day_num 7){
回声“;
$day_count=1;
}
}
不知何故,您在某处执行$var='Tue'
,然后执行$var++
。无法看到代码中如何/在何处发生这种情况,但这就是为什么您有Tue
,Tuf
,Tug
,等等。。。注意e->f->g。。。。你正在增加一个字符串。嗨,马克,代码现在只显示数字,我拿出了它显示的部分(星期二,星期二,星期五,拖船,等等),这是它显示数字回声“$day_num”;您必须使用填充值的数组将该值$daysInWeek
转换为一天,该数组包含与文本值关联的数字键,如:$daysInWeek[1]=“mon”$daysInWeek[2]=“周二”代码>等。。。然后echo$daysInWeek[$day_of u week]代码>@rasclatt不,我没有。那会是什么样子?不知何故,在某个地方,你正在做$var='Tue'
,然后$var++
。无法看到代码中如何/在何处发生这种情况,但这就是为什么您有Tue
,Tuf
,Tug
,等等。。。注意e->f->g。。。。你正在增加一个字符串。嗨,马克,代码现在只显示数字,我拿出了它显示的部分(星期二,星期二,星期五,拖船,等等),这是它显示数字回声“$day_num”;您必须使用填充值的数组将该值$daysInWeek
转换为一天,该数组包含与文本值关联的数字键,如:$daysInWeek[1]=“mon”$daysInWeek[2]=“周二”代码>等。。。然后echo$daysInWeek[$day_of u week]代码>@rasclatt不,我没有。那会是什么样子?