Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marko Schulz  >  Eastern  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file to show the usage of the Eastern class
Class: Eastern
Calculate the Easter related dates
Author: By
Last change: Sample script slightly extended.
Date: 2011-05-20 02:24
Size: 1,651 bytes
 

Contents

Class file image Download
<html>
<head>
    <title>Simple example Easter class</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>

<?php

// variables for Easter class
$cfg['easter'] = array(
    
'year' => 2009,
    
'format' => 'jS F'
);

// load the Easter class
require_once('easter.class.php');


// simple example
try {
    
$year 2011;
    
// get the $easter object an set the year
    
(object) $easter = new Easter($cfg['easter']);

    echo 
"<h3>About Carl Friedrich Gauss</h3>\n<p>".$easter->about()."</p>\n";

    try {
        if ( 
$easter->setVar('year',$year) === FALSE )
            throw new 
Exception('Invalid parameter');
    } catch ( 
Exception $varError ) {
        echo 
"Error: <b>"$varError->getMessage(). "</b> on line "$varError->getLine(). " in "$varError->getFile(). "<br/>\n";
    }

    
// output
    
echo "<h3>Simple example</h3>\nIn $year:<br/> Good Friday is on "$easter->date('goodfriday'). ", <br/>";
    echo 
"Easter Sunday on "$easter->date('eastersunday'). " and <br/>Easter Monday on "$easter->date('eastermonday'). ".<br/>\n";

    
// show class variables
    
$varYear   $easter->getVar('year');
    
$varEaster $easter->getVar('easter');
    
$varFormat $easter->getVar('format');
    echo 
"<h3>Class variables:</h3>\nYear = ".$varYear."<br/> Easter = ".$varEaster."<br/> Format = ".$varFormat."<br/>\n";

    if ( 
$varTest $easter->getVar('fail') === FALSE // test failure of call to getVar()
        
throw new Exception('getVar() failed');

} catch ( 
Exception $error ) {
    echo 
"Error: "$error->getMessage(). " on line: "$error->getLine(). " in "$error->getFile(). "<br/>\n";
}

?>

</body>
</html>