T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 1
  Today Visit: 127
  Total Visitor : 285993
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

Simple Calendar

Author : zavaboy

A simple calendar that is identical to what is returned with 'cal' in the *nix shell.

PHP Example :

<?php
/*
Not copyrighted, use as you wish!
Don't hold me responsible if something bad happens.
Use this code at your own risk.

Nov.24.2005: Comments added.
*/

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 "\n"$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),21,' ',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) == || $day == date('t',$ut))
      
$out .= $zn; else $out .= $zt;

    
// If last day, stop.
    
if ($day == date('t',$ut))
      break;
  }

  
// Return the calendar!
  
return $out;
}
?>



Usage Example:

PHP Example :

<?php 
echo calendar(); // Returns current month. 
echo calendar(strtotime('last year')); // Returns this month last year. 
echo calendar(mktime(0,0,0,2,1,1998)); // Returns February 1998. 
?>



Other Example
Time Convert Function
Date Convert Function


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007