PHPRO.ORG

Zodiac Class

Zodiac Class

These small and easy to use class will detirmine the Zodiac Star Sign for a give month and date.


<?php
/**
 *
 * @class Zodiacal
 *
 * @copyright Copyright (C) 2008 PHPRO.ORG. All rights reserved.
 *
 * @version //autogentag//
 *
 * @license new bsd http://www.opensource.org/licenses/bsd-license.php
 *
 * @filesource
 *
 * @package zodiacal
 *
 * @Author Kevin Waterson
 *
 */

class Zodiacal{

    
/*
     * @array $signs
     */
    
private $signs;

    
/*
     * @array blocks
     */
    
private $blocks;

    
/*
     * @constructor - set a few properties
     */
    
public function __construct()
    {
        
$this->signs = array(
            
=> 'Capricorn',
            
=> 'Aquarius',
            
=> 'Pisces'
            
=> 'Aries',
            
=> 'Taurus',
            
=> 'Gemini',
            
=> 'Cancer',
            
=> 'Leo',
            
=> 'Virgo',
            
10 => 'Libra',
            
11 => 'Scorpio',
            
12 => 'Sagittarius');

        
$this->blocks = array(
            
13=>356,
            
12=>326,
            
11=>296,
            
10=>266,
            
9=>235,
            
8=>203,
            
7=>172,
            
6=>140,
            
5=>111,
            
4=>78,
            
3=>51,
            
2=>20,
            
1=>0);
    }

    
/*
     *
     * @set day number
     *
     * @access private
     *
     * @param int $month
     *
     * @param int $day
     *
     * @return it
     *
      */
    
private function getDayNumber($month$day)
    {
        
/*** get the day number ***/
        
$num getdate(mktime(2,0,0,$month,$day));
                return 
$num['yday'];
    }


    
/*
     *
     * @Get Zodiac Star Sign
     *
     * @access public
     *
     * @param int $month
     *
     * @param int $day
     *
     * @return string
     *
     */
    
public function GetSign($month$day)
    {
        
$day_num $this->getDayNumber($month$day);
        
/*** loop through the day blocks ***/
        
foreach ($this->blocks as $key=>$value)
        {
            if (
$day_num>=$value)
            break;
        }
        
/*** dont forget capricorn ***/
        
$key = ($key>12) ? $key
        return 
$this->signs[$key]; 
    }      
}

?>

Example Usage


<?php

$zodiacSign
=new Zodiacal(); 
echo 
$zodiacSign->GetSign(4,20);

?>

Demonstration

Aries