欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP简单日历实例

程序员文章站 2022-05-30 19:09:30
...

?php /* * PHP简单日历实例 * 作者: 多菜鸟 * 邮箱: kingerq AT msn DOT com * 来源: http://blog.csdn.net/kingerq/ * 创建时间: 2008-01-03 **/ $date = preg_match(//d{4}/-/d{2}/-/d{2}/, $_GET[YMD]) ? $_GET[YMD] : date( Y-m-d ); $thisYear = date(

/*
* PHP简单日历实例
* 作者: 多菜鸟
* 邮箱: kingerq AT msn DOT com
* 来源: http://blog.csdn.net/kingerq/
* 创建时间: 2008-01-03
**/

$date = preg_match("//d{4}/-/d{2}/-/d{2}/", $_GET["YMD"]) ? $_GET["YMD"] : date( "Y-m-d" );
$thisYear = date( "Y", strtotime( $date) );
$thisMonth = date( "m", strtotime( $date) );
$firstDay = date( "w", strtotime( $thisYear."-".$thisMonth."-01" ) );
$monthNum = date( "t", strtotime( $date) );
?>


Calendar






"><<Last Year
"><Last Month

=$date?>

">Next Month>
">Next Year>>
Today












$i = 1;
$num = 0;
while( 1 ) {//row
?>

while( $i while( $firstDay ) {//empty in front
?>

$firstDay--;
$num++;
}
$daykey = str_pad($i, 2, 0, STR_PAD_LEFT);
$thisDay = date("Y-m-d", strtotime($thisYear."-".$thisMonth."-".$daykey) );
$week = date("w", strtotime($thisDay));
$className = ( $week%7 == 0 ? " class='sunday'" : ( $week%7 == 6 ? " class='saturday'" : ""));
?>

$i++;
$num++;
if( $num % 7 == 0 ) break;
}
while( $num % 7 != 0 ) {//list empty cell
?>

$num++;
}
?>

if( $i >= $monthNum ) break;
}
?>









SUN
MON TUE WED THU FRI
SAT
>
>=$i ?>