用PHP生成日历
1. [文件]
calendar.class.php
year = date('Y');
$this->month = date('m');
$vars = get_class_vars(get_class($this));
foreach ($options as $key=>$value) {
if (array_key_exists($key, $vars)) {
$this->$key = $value;
}
}
}
function display()
{
echo '';
$this->showChangeDate();
$this->showWeeks();
$this->showDays($this->year,$this->month);
echo '
';
}
private function showWeeks()
{
echo '
';
foreach($this->weeks as $title)
{
echo '| '.$title.' | ';
}
echo '
';
}
private function showDays($year, $month)
{
$firstDay = mktime(0, 0, 0, $month, 1, $year);
$starDay = date('w', $firstDay);
$days = date('t', $firstDay);
echo '
';
for ($i=0; $i<$starDay; $i++) {
echo '| | ';
}
for ($j=1; $j<=$days; $j++) {
$i++;
if ($j == date('d')) {
echo ''.$j.' | ';
} else {
echo ''.$j.' | ';
}
if ($i % 7 == 0) {
echo '
';
}
}
echo '
';
}
private function showChangeDate()
{
$url = basename($_SERVER['PHP_SELF']);
echo '
';
echo '| '.'<<'.' | ';
echo ''.'<'.' | ';
echo ' | ';
echo ''.'>'.' | ';
echo ''.'>>'.' | ';
echo '
';
}
private function preYearUrl($year,$month)
{
$year = ($this->year <= 1970) ? 1970 : $year - 1 ;
return 'year='.$year.'&month='.$month;
}
private function nextYearUrl($year,$month)
{
$year = ($year >= 2038)? 2038 : $year + 1;
return 'year='.$year.'&month='.$month;
}
private function preMonthUrl($year,$month)
{
if ($month == 1) {
$month = 12;
$year = ($year <= 1970) ? 1970 : $year - 1 ;
} else {
$month--;
}
return 'year='.$year.'&month='.$month;
}
private function nextMonthUrl($year,$month)
{
if ($month == 12) {
$month = 1;
$year = ($year >= 2038) ? 2038 : $year + 1;
}else{
$month++;
}
return 'year='.$year.'&month='.$month;
}
}
2. [文件]
demo.php
$_GET['year'],
'month' => $_GET['month'],
);
}
$params['url'] = 'demo.php';
require_once 'calendar.class.php';
?>
日历demo
display();
?>
3. [图片] sample.jpg
AI帮个忙
多功能AI小工具,帮你快速生成周报、日报、邮、简历等
下载
