<?
function calendar($time=NULL){
// $time must be a valid unix timestamp to be used.
if (!preg_match('#[0-9]{1,10}#i',$time))
$time = time();
// Make some useful vars.
$zt = ' '; $zn = "
"; $out = ''; $day = 0;
$wd = array('Su','Mo','Tu','We','Th','Fr','Sa');
$utd = 86400; // Seconds in a day.
// Get the year and month based on $time.
$info = explode(' ',date('Y m',$time));
// Unix timestamp of the first and last day of the month.
$ut1 = mktime(0,0,0,$info[1],1,$info[0]);
$ut2 = mktime(0,0,0,$info[1],date('t',$ut),$info[0]);
// Output line 1: Full month and year.
$out .= rtrim(str_pad(date('F Y',$ut1),20,' ',STR_PAD_BOTH)).$zn;
// Output line 2: Days of the week.
for ($i=0;$i<count($wd);$i++){
$out .= $wd[$i];
if ($i < count($wd)-1) $out .= $zt;
}
$out .= $zn;
// Output lines 3 and up.
for ($ut=$ut1;$ut<=$ut2;$ut+=$utd){
$day++;
// Output line 3: Empty days.
if ($day == 1){
for ($i=0;$i<date('w',$ut);$i++){
$out .= ' '.$zt;
}
}
// Output: The day.
$out .= str_pad($day,2,' ',STR_PAD_LEFT);
// Output: Newline or tab.
if (date('w',$ut) == 6 || $day == date('t',$ut))
$out .= $zn; else $out .= $zt;
// If last day, stop.
if ($day == date('t',$ut))
break;
}
// Return the calendar!
return $out;
}
?>
kaynak: ordan burdan
Tags: bedava, nasıl, nedir, php, program, Scriptler, Scriptler, takvimPhp - Takvim (scriptler, programlama, nasıl, nedir?, bedava) konusu
Benzer yazılar:
- Benzer yazı yok