澳门新葡萄京娱乐场php简单的日历程序

?phpclass Calendar{ /** * @desc :简单的日历类,供大家学习 * @author
:Allen Wu * @Email :wukewei00o@126.com * @Date :2008-09-12 * @version
:v1.0 */ /*定义变量年、月、日*/ private $year,$month,$day;
/*定义数组星期并初始化*/ private $week =
array(星期日,星期一,星期二,星期三,星期四,星期五,星期六);
/*定义数组月份并初始化*/ private $monthes = array(01=一月, 02=二月,
03=三月, 04=四月, 05=五月, 06=六月, 07=七月, 08=八月, 09=九月, 10=十月,
11=十一月, 12=十二月 ); function __construct(){ $year =
isset($_POST[‘year’]) ? $_POST[‘year’] : date(‘Y’); $month =
isset($_POST[‘month’]) ? $_POST[‘month’] : date(‘m’); $day =
isset($_POST[‘day’]) ? $_澳门新葡萄京娱乐场,POST[‘day’] : date(‘d’); $this-set($year,
$month, $day); } /** * @desc 设置年、月、日的值 * @params String
$year * @params String $month * @params String $day * @return */
private function set($year, $month, $day){ $this-year = $year;
$this-month = $month; $this-day = $day; } /** * @desc
获取年、月、日的值并以数组形式返回 * @params Array $info * @retrun
Array */ function get(array $info){ $info = array(‘year’ = $this-year,
‘month’= $this-month, ‘day’ = $this-day); return $info; } /** * @desc
获得指定日期的星期值 * @params String $year * @params String $month *
@params String $day * @return String */ private function
getWeek($year, $month, $day){ $weekday =
date(w,mktime(0,0,0,$month,$day,$year)); return $weekday; } /** *
输出日历,有兴趣的可以改进! *
其实这不是一个方法,不希望在类里出现html和样式 *
有兴趣的可以改进下!给大家起个抛砖引玉的作用 * */ public function
out(){ $firstDay = $this-getWeek($this-year, $this-month, 1); echo div
style=margin:0;border:1 solid black;width:300;font:9pt. form
action=$_SERVER[PHP_SELF] method=post style=margin:0. select
name=month onchange=this.form.submit();; /*打印12个月*/ for($month =
1; $month = 12; $month++){ $tmp = sprintf(%02d, $month); if(strcmp($tmp,
$this-month) == 0){ $select = selected style=background-color:#c0c0c0;
}else{ $select = ; } echo option value=$tmp
$select.$this-monthes[$tmp]./optionrn; } echo /selectselect name=year
onchange=this.form.submit();; /*打印年份,前后10年*/ for($year =
$this-year – 10; $year $this-year + 10; $year++){ if($year 2037){break;}
if($year 1970){continue;} if(strcmp($year, $this-year) == 0){ $select =
selected style=background-color:#c0c0c0; }else{ $select = ; } echo
option value=$year $select$year/optionrn; } echo /select/formtable
border=0 align=center; /*打印星期标头*/ for($week = 0; $week
count($this-week); $week++){ echo td.$this-week[$week]; }
/*打印所有日期*/ for($tmpd = 1; $tmpd =
date(t,mktime(0,0,0,$this-month,$this-day,$this-year)); $tmpd++){
if(strcmp($tmpd, $this-day) == 0){ //获得当前日期,做标记
$flag=bgcolor=’#ff0000′; }else{ $flag= bgcolor=’#ffffff’; } if($tmpd
== 1){ echo tr; //补充打印 for($i = 0; $i $firstDay; $i++){ echo td; } }
if(strcmp($this-getWeek($this-year, $this-month, $tmpd), 0) == 0){ echo
trtd align=center $flag$tmpd; }else{ echo td align=center $flag$tmpd; }
} echo /table/div; }}$obj = new Calendar();$obj-out();?

<?php教程

class Calendar
{
 var $month;
 var $year;

    function __construct($year,$month)
    {
     $this->year=$year;
  $this->month=$month;
 }

 function endday()
 {
 
$daydate=date(“d”,mktime(0,0,0,$this->month,35,$this->year));
  $endday=35-$daydate;
  return $endday;
 }
 
 function oneday_week()
 {
 
$oneday_week=date(“w”,mktime(0,0,0,$this->month,1,$this->year));
  return $oneday_week;
 }
 
 function title_link()
 {
  if(!isset($this->month) && !isset($this->year))
  {
   $this->year  = date(“Y”);
   $this->month = date(“m”);
        }
       
 
  $lastmonth=$this->month-1;
  $nextmonth=$this->month+1;
  $lastyear=$this->year;
  $nextyear=$this->year;

        if($this->month <= 1)
        {
         $lastmonth=12;
   $nextmonth=$this->month+1;
   $lastyear=$this->year-1;
   $nextyear=$this->year;
  }
        elseif ($this->month >= 12)
        {
         $lastmonth=$this->month-1;
         $nextmonth=1;
   $lastyear=$this->year;
   $nextyear=$this->year+1;
        }

        $str =”<td colspan=’2′><div align=’center’><a
href=$PHP_SELF?year=”.$lastyear.”&month=”.$lastmonth.”&><<<</a></div></td>”;
  $str.=”<td colspan=’3′><div
align=’center’>”.$this->year.”–“.$this->month.”</div></td>”;
  $str.=”<td colspan=’2′><div align=’center’><a
href=$PHP_SELF?year=”.$nextyear.”&month=”.$nextmonth.”&>>>></a></div></td>”;
  return $str;
 }
 
 
 function Show_Calendar()
 {
        echo “<table width=’181′ border=5><tr
class=’tr.title’>”.$this->title_link().”</tr><tr>”;
        $weekarray=array(“日”,”一”,”二”,”三”,”四”,”五”,”六”);
       
        for($k=0;$k<=6;$k++)
        {
         echo “<td><div
align=’center’>”.$weekarray[$k].”</div></td>”;
        }
        echo “</tr>”;
       
        for($i=0;$i<=5;$i++)
        {
         echo “<tr>”;
         for($j=1;$j<=7;$j++)
         {
    $math=( $j – $this->oneday_week() ) + 7 * $i;
   
          echo “<td><div align=’center’>”;
   
          if($math <= $this->endday() and $math>=1)
    {
         echo $math;
    }
   
         echo “</div></td>”;
         }   
         echo “</tr>”;    
        }
  echo “</table>”;
         
 }
}

/*$calendar=new Calendar($_GET[‘year’],$_GET[‘month’]);
//$calendar->month=$_GET[‘month’];
//$calendar->year=$_GET[‘year’];
$calendar->Show_Calendar();*/

//第二个

?>

实例二

<?php
header(“content-type:text/html;charset=utf-8”);
?>
<meta http-equiv=”content-type”
content=”text/html;charset=utf-8″>

<link
href=”statics/css教程/zhaoshang.css”
rel=”stylesheet” type=”text/css”>
<div class=”rili”>
<?php
if(!empty($_GET)){
    $year = isset($_GET[‘year’])?$_GET[‘year’]:date(‘y’);
    $month = isset($_GET[‘month’])?$_GET[‘month’]:date(‘m’);
 $day = isset($_GET[‘day’])?$_GET[‘day’]:date(‘d’);
}
if(empty($year)){
    $year = date(‘Y’);
}
if(empty($month)){
    $month = date(‘m’);
}

if(empty($month)){
    $days = date(‘d’);
}

$start_weekday = date(‘w’,mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date(‘t’,mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array(‘日’,’一’,’二’,’三’,’四’,’五’,’六’);
$i = 0;
$k = 1;
$j = 0;
echo ‘<table >’;
echo ‘<tr><td colspan = 7 style =”text-align:center;
width:250px; background:#d5e5f6; border-bottom:1px solid
#333366;”>’.$year.’年’.$month.’月’.'</td></tr>’;
echo ‘<tr>’;
for($i = 0;$i < 7;$i++){
    echo ‘<td>’.$week[$i].'</td>’;
}
echo ‘</tr>’;
echo ‘<tr>’;
for($j = 0;$j < $start_weekday;$j++){
    echo ‘<td style=”color:#f1f8fc;”>’.$j.'</td>’;
}
while($k <= $days){
    if($k == $day){
        echo ‘<td style=”color:red”><a
href=”?year=’.$year.’&month=’.$month.’&day=’.$k.'”><span
style=”color:red”>’.$k.'</span></a></td>’;
    }else{
        echo ‘<td><a
href=”?year=’.$year.’&month=’.$month.’&day=’.$k.'”>’.$k.'</a></td>’;
    }
    if(($j+1) % 7 == 0){
        echo ‘</tr><tr>’;
    }
    $j++;
    $k++;
}
while($j % 7 != 0){
    echo ‘<td style=”color:#f1f8fc;”>’.$j.'</td>’;
    $j++;
}
echo ‘</tr>’;

echo ‘<tr style=”background:#d5e5f6;”>’;
echo “<td><a
href=?”.lastYear($year,$month).”>”.'<<‘.'</a></td>’;
echo “<td><a
href=?”.lastMonth($year,$month).”>”.'<‘.'</a></td>’;
echo ‘<td colspan = 3 style=”width:105px;” >’;
echo ‘<form name = “myform” method = “GET”>’;
echo ‘<select name = year 
class=”year”>’;
for($start_year = 1970;$start_year<2039;$start_year++){
 $selected=”;
 if( $year== $start_year ) { $selected=’selected’; }
 echo ‘<option value =’. $start_year.’
‘.$selected.’>’.$start_year.'</option>’.” nt”;
}
echo ‘</select>’;
echo ‘<select name = month class=”month”>’;
for($start_month = 1;$start_month<=12;$start_month++){
 $selected=”;
 if( $month== $start_month ) { $selected=’selected’;}
 echo ‘<option value = ‘.$start_month.’
‘.$selected.’>’.$start_month.'</option>’.” nt”;
}
echo ‘</select>’;
/*echo ‘月’;*/
/*echo ‘<input type = “submit” name = “search” value =
“查询”>’;*/
echo ‘</form>’;
echo ‘</td>’;
echo “<td><a
href=?”.nextYear($year,$month).”>”.’>>’.'</a></td>’;
echo “<td><a
href=?”.nextMonth($year,$month).”>”.’>’.'</a></td>’;
echo ‘</tr>’;
echo ‘</table>’;

function lastYear($year,$month){
 $year = $year-1;
 return “year=$year&month=$month”;
}
function lastMonth($year,$month){
 if($month == 1){
  $year = $year -1;
  $month = 12;
 }else{
  $month–;
 }
 return “year=$year&month=$month”;
}
function nextYear($year,$month){
 $year = $year+1;
 return “year=$year&month=$month”;
}
function nextMonth($year,$month){
 if($month == 12){
  $year = $year +1;
  $month = 1;
 }else {
  $month++;
 }
 return “year=$year&month=$month”;
}

?>
</div>
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注