电脑安全

您当前的位置:主页 > 电脑安全 >

php简单的日历程序-网络编程

来源:[db:来源]标题:   星期    编辑:电脑技术全能网 时间:2019-09-20 12:29

原标题: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]."</option>rn"; } echo "</select><select 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</option>rn"; } echo "</select></form><table 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 "<tr><td align=center $flag>$tmpd"; }else{ echo "<td align=center $flag>$tmpd"; } } echo "</table></div>"; }}$obj = new Calendar();$obj->out();?>

上一篇:PHP 5.0对象模型深度探索之起步-网络编程

下一篇:没有了