WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Generate HTML Calendar of a month of year
Categories : PHP, Calendar, PHP Classes Click here to Update Your Picture
Ben Yacoub Hatem
Date : Jun 13th 2004
Grade : 3 of 5 (graded 3 times)
Viewed : 41305
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 




calendar class :

@package
@author Ben Yacoub Hatem <[email protected]>
@copyright Copyright PHPTunisie.net (c) 2004
@version $Id$ - 09/06/2004 06:39:31 - calendar.php
@access public


<?php
class calendar{
   
/**
     * Constructor
     * @access protected
     */
   
function calendar(){
         
    }
     
   
/**
     * calendar::html_month_calendar()
     *
     * @param integer $m        The month value, could be returned with $m = date("m");
     * @return
     **/
   
function html_month_calendar($m = "",$y = ""){     
        if (
trim($m) == "") {
           
$m = date($m);
        }
        if (
trim($y)=="") {
           
$y = date("Y");
        }
       
$curr_month = date("m");
       
$d = date("d");
        if (
$m==1) {
           
$m_1 = 12;
           
$y_1 = $y-1;
        } else {
           
$m_1 = $m-1;
           
$y_1 = $y;
        }
       
$to = mktime(0,0,0,$m_1,0,$y_1);
       
$days_in_month = strftime ("%d",$to);
       
$from = mktime(0,0,0,$m,1,$y);
         
       
$from_a = getdate($from);
       
$to_a = getdate($to);
       
$calendar = "\n<table bgcolor=white cellpadding=2 cellspacing=0>
<tr>
    <th>Dim</th>
    <th>Lun</th>
    <th>Mar</th>
    <th>Mer</th>
    <th>Jeu</th>
    <th>Ven</th>
    <th>Sam</th>
</tr>\n"
;

       
$Days = 0;
         
        for(
$i = 1; $i <= 6; $i++){
           
$calendar .= "<tr>\n";
            for(
$j = 0; $j <= 6 ; $j++){
                if (
$d == ($Days+1) and $curr_month==$m) {
                   
$b1 = "<b>";$b2 = "</b>";
                } else
$b1 = "";$b2 = "";
                 
                if (
$from_a["wday"]==$j and $Days==0) {
                   
$Days++;
                   
$calendar .= "<td>$b1 $Days $b2</td>";
                } elseif(
$Days==0) {
                   
$calendar .= "<td></td>";
                } else {
                   
$Days++;
                    if (
$Days<=$days_in_month) {
                       
$calendar .= "<td>$b1 $Days $b2</td>";
                    } else {
                       
$calendar .= "<td></td>";
                    }
                }
            }
// for
           
$calendar .= "</tr>\n";
        }
// for
       
$calendar .= "</table><center>\n";
         
        return
$calendar;
    }
     
   
/**
     *
     * @access public
     * @return void
     **/
   
function html_year_calendar($y = ""){
        if (
trim($y)=="") {
           
$y = date("Y");
        }
         
       
$year_calendar = "<table bgcolor=white cellpadding=2 cellspacing=0 width=100% border=1>\n<tr>\n";
         
        for(
$i = 1; $i <= 12; $i++){
           
$year_calendar .= "<td valign=top>Mois $i <br>".$this->html_month_calendar($i,$y )."</td>";
            if (
$i == 3 or $i == 6 or $i == 9) {
               
$year_calendar .= "</tr>\n<tr>\n";
            }
        }
// for
         
       
$year_calendar .= "</tr><table>";
         
        return
$year_calendar;
    }
     
     
}

$cal = new calendar;
//echo $cal->html_month_calendar();
echo $cal->html_year_calendar();

?>




Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
PHP Zip Utility
Categories : PHP, PHP Classes, Compression
These PHP Classes Check if a host is alive using various methods.
Categories : PHP, PHP Classes, Sockets, CURL
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories
Building a basic error handler with custom error types
Categories : PHP, PHP Classes, Errors and Logging
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
 Niels Oesten wrote : 1131
Works fine, but I really think you should have created it according to the standard ISO 8601. That is with Monday as the first day-of-week. Otherwise week numbers make no sense. 
 
 matthew waygood wrote :1132
Using system locale, you can set the month and weekday names to the current language. So a quick alteration to the code has been done to accoodate this.

&lt;?php 

/** 
* calendar class : 

* @package 
* @author Ben Yacoub Hatem &lt;[email protected]&gt; 
* @copyright Copyright PHPTunisie.net (c) 2004 
* @version $Id$ - 09/06/2004 06:39:31 - calendar.php 
* @access public 
**/ 
class calendar{ 
    /** 
     * Constructor 
     * @access protected 
     */ 
    function calendar(){ 
          
    } 
      
    /** 
     * calendar::html_month_calendar() 
     * 
     * @param integer $m        The month value, could be returned with $m = date("m"); 
     * @return 
     **/ 
    function html_month_calendar($m = "",$y = ""){      
        if (trim($m) == "") { 
            $m = date($m); 
        } 
        if (trim($y)=="") { 
            $y = date("Y"); 
        } 
        $curr_month = date("m"); 
        $d = date("d"); 
        if ($m==1) { 
            $m_1 = 12; 
            $y_1 = $y-1; 
        } else { 
            $m_1 = $m-1; 
            $y_1 = $y; 
        } 
        $to = mktime(0,0,0,$m_1,0,$y_1); 
        $days_in_month = strftime ("%d",$to); 
        $from = mktime(0,0,0,$m,1,$y); 
          
        $from_a = getdate($from); 
        $to_a = getdate($to);

        $calendar = "\n&lt;table bgcolor=white cellpadding=2 cellspacing=0&gt;&lt;tr&gt;";
        $sunday=strtotime("-".date("w")." days");
        for($loop=0;$loop&lt;7;$loop++)
        {
            $calendar.="&lt;th&gt;".strftime("%a" ,strtotime("+".$loop." days",$sunday))."&lt;/th&gt;";
        }
        $calendar.="&lt;/tr&gt;\n"; 

        $Days = 0; 
          
        for($i = 1; $i &lt;= 6; $i++){ 
            $calendar .= "&lt;tr&gt;\n"; 
            for($j = 0; $j &lt;= 6 ; $j++){ 
                if ($d == ($Days+1) and $curr_month==$m) { 
                    $b1 = "&lt;b&gt;";$b2 = "&lt;/b&gt;"; 
                } else $b1 = "";$b2 = ""; 
                  
                if ($from_a["wday"]==$j and $Days==0) { 
                    $Days++; 
                    $calendar .= "&lt;td&gt;$b1 $Days $b2&lt;/td&gt;"; 
                } elseif($Days==0) { 
                    $calendar .= "&lt;td&gt;&lt;/td&gt;"; 
                } else { 
                    $Days++; 
                    if ($Days&lt;=$days_in_month) { 
                        $calendar .= "&lt;td&gt;$b1 $Days $b2&lt;/td&gt;"; 
                    } else { 
                        $calendar .= "&lt;td&gt;&lt;/td&gt;"; 
                    } 
                } 
            } // for 
            $calendar .= "&lt;/tr&gt;\n"; 
        } // for 
        $calendar .= "&lt;/table&gt;&lt;center&gt;\n"; 
          
        return $calendar; 
    } 
      
    /** 
     * 
     * @access public 
     * @return void 
     **/ 
    function html_year_calendar($y = ""){ 
        if (trim($y)=="") { 
            $y = date("Y"); 
        } 
          
        $year_calendar = "&lt;table bgcolor=white cellpadding=2 cellspacing=0 width=100% border=1&gt;\n&lt;tr&gt;\n"; 
          
        for($i = 1; $i &lt;= 12; $i++){ 
            $month_name=strftime("%B" ,mktime(1,1,1,$i));
            $year_calendar .= `&lt;td valign="top" align="center"&gt;`.$month_name.`&lt;br&gt;`.$this-&gt;html_month_calendar($i,$y ).`&lt;/td&gt;`; 
            if ($i == 3 or $i == 6 or $i == 9) { 
                $year_calendar .= "&lt;/tr&gt;\n&lt;tr&gt;\n"; 
            } 
        } // for 
          
        $year_calendar .= "&lt;/tr&gt;&lt;table&gt;"; 
          
        return $year_calendar; 
    } 
      
      


$cal = new calendar; 
//echo $cal-&gt;html_month_calendar(); 
echo $cal-&gt;html_year_calendar(); 

?&gt;