note 105654 added to function.date
| From: | gothamxi at gmail dot com | Date: | Sun, 04 Sep 2011 22:07:05 +0000 |
| Subject: | note 105654 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182939@lists.php.net to get a copy of this message | ||
simple calendar generator:
<?php
$dw=date(N);//this day of the week, numeric
$d=date(j);//this date
$m=date(m);//this month
$y=date(o);//this year
echo "<div id='CALENDAR DIV'><span
style='font-size:20px;display:block;width:100%;text-align:center;'>";
echo date("F",mktime(0, 0, 0, $m, 1, $y));
echo "</span><table style='border:2px solid
black;border-collapse:collapse;'>";
function mlength($month,$year){
return cal_days_in_month(CAL_GREGORIAN, $month, $year);//finds length of given month
}
$tml=mlength($m,$y);//this month's length
$cc=1;//day of the week counter
$day=1;
$tmd1=date("N", mktime(0, 0, 0, $m, 1, $y));//this month day 1, day of the week, numeric
//write out calendar---------------------------------------------------------------------
//days of the week
$dwcc=1;//counter for days of the week row
while($dwcc<=7){
$dwrow.="<td style='padding:15px;width:150px;height:auto;border:2px solid #333;'
>".date("l", mktime(0, 0, 0, 8, $dwcc, 2011))."</td>\r\n";
$dwcc=$dwcc+1;
}
$tblrows="<tr>\r\n".$dwrow."\r\n</tr>\r\n\r\n";
//last days of last month
if($tmd1!=1){
while($cc<$tmd1){
$tblrows.=(($cc==1)?"<tr>\r\n":"")."<td
style='padding:15px;width:150px;height:150px;border:2px solid black;'
> </td>\r\n";
$cc=($cc==7)?1:$cc+1;
}
}
//this month
while($day<=$tml){
$tblrows.=(($cc==1)?"<tr>\r\n":"")."<td
style='padding:15px;width:150px;height:150px;border:2px solid
black;".(($day==$d)?"background-color:#999;":"")."'
>".$day."</td>\r\n".(($cc==7)?"\r\n</tr>\r\n\r\n":"");
$cc=($cc==7)?1:$cc+1;
$day=$day+1;
}
//first days of next month
if($cc!=7){
while($cc<=7){
$tblrows.="<td style='padding:15px;width:150px;height:150px;border:2px solid
black;'
> </td>\r\n".(($cc==7)?"\r\n</tr>\r\n\r\n":"");
$cc=$cc+1;
}
}
echo $tblrows;
echo "</table></div>";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 123.138.236.204
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/105654
Del: integrated -- https://master.php.net/note/delete/105654/integrated
Del: useless -- https://master.php.net/note/delete/105654/useless
Del: bad code -- https://master.php.net/note/delete/105654/bad+code
Del: spam -- https://master.php.net/note/delete/105654/spam
Del: non-english -- https://master.php.net/note/delete/105654/non-english
Del: in docs -- https://master.php.net/note/delete/105654/in+docs
Del: other reasons-- https://master.php.net/note/delete/105654
Reject -- https://master.php.net/note/reject/105654
Search -- https://master.php.net/manage/user-notes.php