- 没有写之前觉的,写一个日历很神奇,写完之后发现也不过如此,仅仅是几个php函数的组合。不要担心自己不会,只要用心的去想,你就一定可以搞定。就像我计算机的启蒙老师说的,不会的问题一定要认真的去做,认真的去解决,做完了你才突然的发现,因为一给小问题,你学到了很多的东西。
- php日历类
- <?php
class calendar
{
public $mounth; //current mounth
public $year; // current year
function __construct()
{
$this->year = $this->get_year();
$this->mounth = $this->get_mounth();
}
function get_mounth()
{
$mounth = date("n",time());
return $mounth;
}
function get_year()
{
$year = date("Y",time());
return $year;
}
function get_day()
{
$day = date("j",time());
return $day;
}
function get_year_mounth_one_number_week()
{
$mounth_one_day = idate("w",mktime(0,0,0,$this->mounth,1,$this->year));
return $mounth_one_day;
}
function get_mounth_total_days()
{
$total_days = idate("t",mktime(0,0,0,$this->mounth,1,$this->year));
return $total_days;
}
function mounth_num_is_week($day)
{
$week = idate("w",mktime(0,0,0,$this->mounth,$day,$this->year));
return $week;
}
function display()
{
$array = array("日","一","二","三","四","五","六");
echo "<table border = '0'><tr>";
foreach($array as $day)
{
echo "<td>".$day."</td>";
}
echo "</tr><tr>";
$i=0;
while($i< $this->get_year_mounth_one_number_week())
{
echo "<td> </td>";
$i++;
}
$j=1;
while($j<=$this->get_mounth_total_days())
{
if($j == $this->get_day())
{
echo "<td bgcolor='red'>".$j."</td>";
}
else
{
echo "<td>".$j."</td>";
}
if($this->mounth_num_is_week($j) == 6)
{
echo "</tr><tr>";
}
$j++;
}
echo "</tr></table>";
}
}
?>
php日历类
最新推荐文章于 2022-10-01 16:00:46 发布