Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2005, 15:58
Avatar de dwaks
dwaks
 
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 8 meses
Puntos: 15
Solo hize de entrar a internet en google puse calendario php y salieron un monton de verdad esa herramienta ayuda mucho y deberia ser la primera opcion a buscar.

Aqui te dejo el codigo de lo que encontre.

Código PHP:
<?php

/*
Author: Vardhan Mudunuru (aka exacube)
Date: January 15th, 2005

Feel free to rip and dip this code ;)
*/

// $leap contains 1 if this is a new year. else, 0
$leap=date("l");

// Set $num_days as an array containing all the months and the number of days they have this year.
$num_days["January"]=31;

// If this is a leap year, February should have 29 days. else, 28
$num_days["February"]=($leap == 29 28);

$num_days["March"]=31;
$num_days["April"]=30;
$num_days["May"]=31;
$num_days["June"]=30;
$num_days["July"]=31;
$num_days["August"]=31;
$num_days["September"]=30;
$num_days["October"]=31;
$num_days["November"]=30;
$num_days["December"]=31;

// $days contains all the days in a week.. The use of this array will be examined later
$days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

// Today's date in number (suchas 21th or whatever).
// $tnc will be used in a loop
$today_num $tnc date("j");
// Today's day of the week (eg: Sat)
$today_day=date("D");

// $tdc contains the index number of today in $days
// Why? you'll find out..
$tdc=array_search(date("D"),$days);

// This is loop is used to get the day of the week on the 1st day of this month (eg: January 1st)
// $tdc is the day of the week in number (the index number in $days)
// $tnc is decreased until it hits 1 (the first day of the month)
// $tdc is also decreased if it goes below 0 (sunday), then it is set to 6 (saturday)
while ($tnc 1) {
    
    
$tdc--;
    if (
$tdc 0) { $tdc=6; }
        
    
$tnc--;
    
}

// set $counter_day the first day of the month (eg: Saturday)
$counter_day=$days[$tdc];

// set $counter_day_num to 1 (the first day of the month... Goes all the way up to 31 depending on the month)
$counter_day_num=1;

// $total_days contains the number of days in this month.. that info is in the $num_days array
$total_days=$num_days[date("F")];

// $on is the column that we are in.. there are 7 columns: Sun, Mon, ... Sat
// when $on hits 6 (which is Sat), a new row is made (<tr></tr> html stuff), and we're on the first column (which is Sun)
// starts with 0, and not 1.. I like to follow the default standards
$on=0;

// Just the title.. displays the month and the year
$date_display_title="<b>"date("F")."</b> (<i><font size=1 color=green>".date("Y")."</font></i>)";

// Creates the table with 7 columns
echo "
    <table border=0 cellpadding=3 cellspacing=1>
    <tr><td colspan=7 class=calender_title>{$date_display_title}</td></tr>
    <tr>
    <td><b>S</b></td>
    <td><b>M</b></td>
    <td><b>T</b></td>
    <td><b>W</b></td>
    <td><b>T</b></td>
    <td><b>F</b></td>
    <td><b>S</b></td>
    </tr>
    <tr>
"
;

// This is the loop.. starts the the first day of the month and works its way up to the last day of the month
while ($counter_day_num <= $total_days) {
    
    
// create a new row if we're at the last column (which is Saturday)
    
if ($on 6) { $on=0; echo "</tr><tr>"; }
    
    
/* Jan 1st 2005 is on Saturday. We're on the Monday column,
        so leave this column blank, go to the next column, and start again from the loop's condition
    */
    
if ($counter_day != $days[$on]) { echo "<td>&nbsp;</td>"$on++; continue; }
    
    
/* if we are display a date thats not yet been past (which is the future), then dull down the colors
        For example, if its 16th today, and we are displaying the 17th, then set the text color to grey
    */
    
if (isset($dull)) {
        echo 
"<td style='background: rgb(220,220,220);'><font style='color: grey'>{$counter_day_num}</font></td>";
    }
    
    
/*
    If we are not displaying the future dates, then display it normally.
    If we are displaying today's date, set $dull as true so the dates that we dislay from here on are dull-colored
    */
    
else {
        echo 
"<td style='background: rgb(230,230,230);' align=center>"$counter_day_num ."</td>";
        if (
$counter_day_num == date("j")) { $dull=true; }
    }
    
    
// Move on to the next day, if all goes well
    
$counter_day_num++;
    
    
// Move on to the next day of the week's index (refer to the $days array)
    
$next_day=array_search($counter_day,$days) + 1;
    
    
// If its over 6 (saturday), then set it to 0 (sunday) since the 7th index doesn't exist in $days
    
$counter_day=$days[($next_day $next_day)];
    
    
// go to the next column
    
$on++;
}

// close the table..
echo "</tr></table>";

?>