在PHP日历中突出显示当前日期


Highlight current day in PHP calendar

我使用的日历代码来自这个网站:

http://www.startutorial.com/articles/view/how-to-build-a-web-calendar-in-php

如何突出显示当前日期?

我试图在

中添加额外的变量
private function _showDay($cellNumber){
    $today = date('Y-m-d');

if($this->currentDate == '{$today}') { //DO SOMETHING }

我正在考虑创建一个新的CSS类与边框或使用不同的背景颜色。但是它可能与已经定义的类,如'start'或'end'重复。

有什么好主意吗?我想保持简单,如果可能的话不使用JavaScript。

在网页评论区找到

压缩版本:

创建一个新的样式元素

div#calendar ul.dates li.this_today { background-color: black; color: white; }

查找方法

private function _showDay($cellNumber){

并加上:

$today_day = date("d");
$today_mon = date("m");
$today_yea = date("Y");
$class_day = ($cellContent == $today_day && $this->currentMonth == $today_mon && $this->currentYear == $today_yea ? "this_today" : "nums_days");
return '<li class="' . $class_day . '">' . $cellContent . '</li>' . "'r'n";