我知道有类似的主题,但我无法弄清楚如何交换它。
我需要根据我的功能将颜色从颜色改为RED
到目前为止我使用的是:
这是我的功能
<?php
function getHolidays($year = null) {
if ($year == null) {
$year = intval(date('Y'));
}
$easterDate = easter_date($year);
$easterDay = date('j', $easterDate);
$easterMonth = date('n', $easterDate);
$easterYear = date('Y', $easterDate);
$holidays = array(
// These days have a fixed date
date("m-d-Y", mktime(0, 0, 0, 1, 1, $year)),
date("m-d-Y", mktime(0, 0, 0, 1, 6, $year)),
date("m-d-Y", mktime(0, 0, 0, 4, 25, $year)),
date("m-d-Y", mktime(0, 0, 0, 5, 1, $year)),
date("m-d-Y", mktime(0, 0, 0, 6, 2, $year)),
date("m-d-Y", mktime(0, 0, 0, 6, 29, $year)),
date("m-d-Y", mktime(0, 0, 0, 8, 15, $year)),
date("m-d-Y", mktime(0, 0, 0, 11, 1, $year)),
date("m-d-Y", mktime(0, 0, 0, 12, 8, $year)),
date("m-d-Y", mktime(0, 0, 0, 12, 25, $year)),
date("m-d-Y", mktime(0, 0, 0, 12, 28, $year)),
// These days have a date depending on easter
date("m-d-Y", mktime(0, 0, 0, $easterMonth, $easterDay + 1, $easterYear)),
);
sort($holidays);
return $holidays;
}
function holidays_color ($date) {
$holidays = getHolidays();
$weekend = date('w', strtotime($date));
if (in_array($date, $holidays)) {
return "<th color= \"red \">";
} else if ($weekend == 0 || $weekend == 6) {
return "<th color= \"red \">";
} else {
return false;
}
} ?>
然后我根据(holidays_color)函数创建了一个表格来显示一个月的所有日子我需要更改假日和周末的颜色。
这是我的表
<?php
echo "<table class=\"table table-bordered \" id=\"main_table\">";
echo"<TH>Nome utente</TH>";
// creat days of month in table header
$lastday = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
for ($day = 1; $day <= $lastday; $day++) {
holidays_color ($day . "-" . date("m") . "-" . date("Y") );
echo"<TH>";
echo $day ;
echo "</TH>";
}
echo"<TH> Option </TH>"; echo "</table>";
?>
答案 0 :(得分:0)
您的代码中有一些错误请更正..您正在使用d-m-y格式检查假日颜色,但功能是m-d-Y格式..
for ($day = 1; $day <= $lastday; $day++) {
echo holidays_color(date("m"). "-" .$day. "-" .date("Y"));
echo $day ;
echo "</TH>";
}
并将功能假期改为这样的事情,让我知道这是你期望的输出
function holidays_color ($date) {
$holidays = getHolidays();
$weekend = date('w', strtotime($date));
if (in_array($date, $holidays)) {
return "<th style='color:red'>";
} else if ($weekend == 0 || $weekend == 6) {
return "<th style='color:red'>";
} else {
return "<th>";
}
}