<?php
/*
Validate-Calculate Age Class by FergoFrog
Copyright (C) 2009 FergoFrog
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-
1307, USA.
Contact:
Email: projects@fergofrog.com
Web: http://www.fergofrog.com/ or http://projects.fergofrog.com/
*/
//To start the class:
include "vcage.class.php";
$VCAge = new VCAge();
//To validate an age:
$VCAge->VAge(day, month, year); //BOOL returns true when valid and false when invalid
//To calculate an age:
$VCAge->CAge(day, month, year); //INT returns the age as an integer
//To validate then calculate an age (there are 1 methods)
/* First (this is more complex and involves more code)
- This first checks the age is valid then echo's the age
- On failure echo's the error
*/
if ($VCAge->VAge(day, month, year)) echo $VCAge->CAge(day, month, year);
else echo $VCAge->Error;
/* Second (This essentially does what the first method does but incorperated into the one function)
- This incorperates the first into one step it validates then calculates the age
- On success the age will be displayed
- On failure the message "Invalid Age: " then the error message will be displayed
*/
echo $VCAge->V_CAge(day, month, year);
//Calculation will never fail unless you don't give it an integer, or number in a string
//Validation will fail on an invalid Day, Month or Year, for example 29FEB2009, or if you don't give it an integer, or number in a string
//If something fails then it will all be outputed to the Error variable, to display the error:
echo $VCAge->Error;
?> |