这个函数请问怎么改才能让是星期日的日期的颜色为红色,而当前日期是黄色??谢谢

pmaster 北京腾讯科技有限公司 2004-12-06 06:17:04
<?php
/* PHP自动生成月历代码共享
Function Written by Nelson Neoh @3/2004.
For those who wants to utilize this code, please do not remove this remark.
If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board. Thank you.

Function usage: calendar(Month,Year)
*/

//function calendar($MM,$YYYY){
if($MM=="") $MM = date("m");
if($YYYY=="") $YYYY = date("Y");
if($YY=="") $YY = date("Y");
if(checkdate($MM,1,$YYYY)){
$stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
$days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
$firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
$lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
$printDays = $days;
$preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
$preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
$nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
$nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
print("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=220>");
print("<tr><th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."\"><img src=images/leftarrow.png border=0></a></th>");
print("<th colspan=\"5\"><font size=2>".strftime("%Y年%m月",mktime (0,0,0,$MM,1,$YYYY))."</font></th>");
print("<th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."\"><img src=images/rightarrow.png border=0></a></th></tr>");
print("<tr style=\"font-family: Verdana; font-size:x-small\">");
print("<th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>");

$currentDays = 1;
for($a=1;$a<=5;$a++){
print("<tr align=\"left\" valign=\"top\" style=\"font-family: Verdana; font-size:x-small\">");
$diffDays = $firstDay-$lastDay;
if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
for($x=$lastDay;$x>=0;$x--){
$printDays = $days-$x;
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$printDays>$printDays</a></td>");
}
for($z=1;$z<$firstDay-$lastDay;$z++){
print("<td align='center' width=14%> </td>");
}
for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}
} elseif($firstDay!=0 && $currentDays==1){
for($z=1;$z<=$firstDay;$z++){
print("<td align='center' width=14%> </td>");
}
for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}
} else {
for($u=1;$u<=7 && $currentDays<=$days;$u++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}
//在这里加入以下两行
while($u++ <=7)
print("<td> </td>");
}
print("</tr>");
}
print("</table>");
}
//}
?>
这个函数请问怎么改才能让是星期日的日期的颜色为红色,而当前日期是黄色??谢谢
...全文
176 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ccxxcc 2004-12-29
收藏!
快要做这个有这个功能的网站
回复
leinchu 2004-12-29
http://urg.vicp.net/calendar.php别人的够NB的
http://urg.vicp.net/cale.php我的够垃圾的:
<link href="corp.css" rel="stylesheet" type="text/css">
<style type="text/css">
td
{font-size:12px;}
</style>
<script language="JavaScript">
function tm(y,m,d)
{
if (d<10)
{
dd="0"+d
}else
{
dd=d
}
if (m<10)
{
mm="0"+m
}else
{
mm=m
}
tdt=y+""+mm+dd
parent.form1.lookday.value=tdt
parent.form1.submit()
}
</script>
<?php
session_start();
if (isset($HTTP_POST_VARS['year'])&&isset($HTTP_POST_VARS['month'])){
$_SESSION['year']=$HTTP_POST_VARS['year'];
$_SESSION['month']=$HTTP_POST_VARS['month'];
}
if (isset($HTTP_SESSION_VARS['year'])&&isset($HTTP_SESSION_VARS['month'])){
$cur_year = $HTTP_SESSION_VARS['year'];
$cur_month = $HTTP_SESSION_VARS['month'];
}else
{
$cur_year=date("Y");
$cur_month = date("m");
}
?>
<form name="form1" method="post">

<select name="year" id="year">
<option value="2004" selected>2004</option>
<?php

for ($i=2005;$i<2007;$i++)
{
if ($cur_year==$i)
{
echo "\" selected>".$i."\n";
}
else
{
echo "\">".$i."\n";
}
}
?>
</select>
<select name="month" id="month" onChange="form1.submit();">
<option value="1">1</option>
<?php
for ($i=2;$i<13;$i++)
{

if ($cur_month==$i)
{
echo "<option value=\"".$i."\" selected>".$i."\n";
}
else
{
echo "<option value=\"".$i."\">".$i."\n";
}

}
?>
</select>

</form>

<?php


//当前月份第一天零时零分零秒的时间截
$StartTimestamp = mktime(0,0,0,$cur_month,1,$cur_year);


//得到当前月份的第一天是星期几,0忭示星期天?6忭示星期菱
$FirstDayOfWeek = date('w',$StartTimestamp);

//得到当前月份的天数
$DaysOfMonth = date('t',$StartTimestamp);
if (($FirstDayOfWeek)!="0"){
for($i=1;$i<$FirstDayOfWeek;$i++){
$day[] = '';
$i;
}
}

for($j=1;$j<=$DaysOfMonth;$j++){
$day[] = $j;
}

echo "<table border=1 bordercolor=#FF0000>\n";
echo "<tr>\n";
echo "<td>一</td>\n";
echo "<td>二</td>\n";
echo "<td>三</td>\n";
echo "<td>四</td>\n";
echo "<td>五</td>\n";
echo "<td>六</td>\n";
echo "<td>日</td>\n";
echo "</tr>\n";
echo "<tr>\n";

for($k=1;$k<count($day)+1;$k++){
if ($cur_year==date("Y")&&$cur_month == date("m")&&$day[$k-1]==date("d"))
{
$dstr="<font color=00ff00>".$day[$k-1]."</font>";
}else
{
$dstr=$day[$k-1];
}

if($k%7 == 0){
echo "<td><font color=ff0000>".$dstr."</font></a></td>\n";
echo "</tr><tr>\n";
}else
{
echo "<td>".$dstr."</a></td>\n";
}
}

echo "</tr>\n";
echo "</table>\n";
?>
回复
shuzai 2004-12-08
麻烦


<?//日历
$month = date("n");
$year = date("Y");
$weekArray = array("<font color=red>日</font>","一","二","三","四","五","六");
?>
<STYLE>
.cal_table{font-family:Tahoma,Georgia; font-size:12px; border-collapse:collapse;}
.cal_td{border-width:1; border-color:#cccccc; border-style:solid;}
</STYLE>
<table width=210 class=cal_table>
<tr><td align=center colspan=7 bgcolor=#bbbbff class=cal_td>
<?=$year."年".$month."月"?>
</td></tr>
<tr>
<?
foreach($weekArray as $week) echo "<td align=center class=cal_td><b>".$week."</b></td>";
?>
</tr>
<?
$n = 0;
$w = date("w" , mktime(0 , 0 , 0 , $month , 1 , $year));
for($x = 0 ; $x < $w ; $x ++) { //输出首日前表格
echo ($x == 0) ? "<tr>" : "";
echo "<td width=30 class=cal_td> </td>";
$n ++;
}
for($day = 1 ; $day < 32; $day ++) { //输出日期
if(!checkdate($month , $day , $year)) break;
echo ($n==0)?"<tr>":"";
$color = ($day == date("j"))? "yellow" : "white";
$fontColor = ($n==0)? "red" : "#888888";
echo "<td align=center width=30 bgcolor=".$color." class=cal_td><font color=".$fontColor.">".$day."</font></td>";
$n ++;
if($n == 7) {
echo "</tr>";
$n = 0;
}
}
while($n < 7 && $n != 0) { //输出末日后表格
echo "<td width=30 class=cal_td> </td>";
$n++;
}
if($n == 7) echo "</tr>";
?>
</table>
回复
wy2000490 2004-12-07


<?php
/* PHP自动生成月历代码共享
Function Written by Nelson Neoh @3/2004.
For those who wants to utilize this code, please do not remove this remark.
If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board. Thank you.

Function usage: calendar(Month,Year)
*/

//function calendar($MM,$YYYY){
if($MM=="") $MM = date("m");
if($YYYY=="") $YYYY = date("Y");
if($YY=="") $YY = date("Y");
if(checkdate($MM,1,$YYYY)){
$stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
$days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
$firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
$lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
$printDays = $days;
$preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
$preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
$nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
$nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
print("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=220>");
print("<tr><th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."\"><img src=images/leftarrow.png border=0></a></th>");
print("<th colspan=\"5\"><font size=2>".strftime("%Y年%m月",mktime (0,0,0,$MM,1,$YYYY))."</font></th>");
print("<th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."\"><img src=images/rightarrow.png border=0></a></th></tr>");
print("<tr style=\"font-family: Verdana; font-size:x-small\">");
print("<th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>");

$currentDays = 1;
$b = 5;
for($a=1;$a<=$b;$a++){
print("<tr align=\"left\" valign=\"top\" style=\"font-family: Verdana; font-size:x-small\">");
$diffDays = $firstDay-$lastDay;
if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
for($x=$lastDay;$x>=0;$x--){
$b = 6;
print("<td align='center' width=14%> </a></td>");
}

for($z=1;$z<$firstDay-$lastDay;$z++){
print("<td align='center' width=14%> </td>");
}

for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}
} elseif($firstDay!=0 && $currentDays==1){
for($z=1;$z<=$firstDay;$z++){
print("<td align='center' width=14%> </td>");
}

for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}

} else {

for($u=1;$u<=7 && $currentDays<=$days;$u++){
if ($u==1)
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays><font color='#FF0000'>$currentDays</font></a></td>");
else
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}

while($u++ <=7)
print("<td> </td>");
}
print("</tr>");
}
print("</table>");
}

?>


回复
centerstar 2004-12-07
print("<tr style=\"font-family: Verdana; font-size:x-small\">"); 就在style里改
回复
Jah1919 2004-12-07
改成这样:

<?php
/* PHP自动生成月历代码共享
Function Written by Nelson Neoh @3/2004.
For those who wants to utilize this code, please do not remove this remark.
If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board. Thank you.

Function usage: calendar(Month,Year)
*/

//function calendar($MM,$YYYY){
if($MM=="") $MM = date("m");
if($YYYY=="") $YYYY = date("Y");
if($YY=="") $YY = date("Y");
if(checkdate($MM,1,$YYYY)){
$stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
$days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
$firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
$lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
$printDays = $days;
$preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
$preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
$nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
$nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
print("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=220>");
print("<tr><th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."\"><img src=images/leftarrow.png border=0></a></th>");
print("<th colspan=\"5\"><font size=2>".strftime("%Y年%m月",mktime (0,0,0,$MM,1,$YYYY))."</font></th>");
print("<th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."\"><img src=images/rightarrow.png border=0></a></th></tr>");
print("<tr style=\"font-family: Verdana; font-size:x-small\">");
print("<th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>");

$currentDays = 1;
$b = 5;
for($a=1;$a<=$b;$a++){
print("<tr align=\"left\" valign=\"top\" style=\"font-family: Verdana; font-size:x-small\">");
$diffDays = $firstDay-$lastDay;
if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
for($x=$lastDay;$x>=0;$x--){
$b = 6;
print("<td align='center' width=14%> </a></td>");
}

for($z=1;$z<$firstDay-$lastDay;$z++){
print("<td align='center' width=14%> </td>");
}

for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}
} elseif($firstDay!=0 && $currentDays==1){
for($z=1;$z<=$firstDay;$z++){
print("<td align='center' width=14%> </td>");
}

for($y=$firstDay;$y<7;$y++){
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}

} else {

for($u=1;$u<=7 && $currentDays<=$days;$u++){
if ($u==1)
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays><font color='#FF0000'>$currentDays</font></a></td>");
else
print("<td align='center' width=14%><a href=reserve.php?date=$YY$MM$currentDays>$currentDays</a></td>");
$currentDays++;
}

while($u++ <=7)
print("<td> </td>");
}
print("</tr>");
}
print("</table>");
}

?>
回复
wxq4100798 2004-12-07
加一句,if($curr_date == date("%Y-%m-%d"))
$date_color = "yellow";
同理if (week="6" || week = "0")
$week_color = "red";
回复
pmaster 2004-12-07
:)
回复
flyonet 2004-12-07
//function calendar($MM,$YYYY){

这是什么意思?
回复
xuzuning 2004-12-07
这个函数写的太复杂,思路有点问题!
建议换个写法
回复
magicsnake 2004-12-07
研究一下
回复
pmaster 2004-12-07
Jah1919,当前日期是黄色没有!!!
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2004-12-06 06:17
社区公告
暂无公告