Home >php教程 >php手册 >PHP简单日历实例

PHP简单日历实例

WBOY
WBOYOriginal
2016-06-06 19:56:441313browse

?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



 
   
     
 

"><
">



">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 ?>
  
 
             


 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn